diff --git a/.gitignore b/.gitignore index 5bbb9107e6c09..06e45f3c3c109 100644 --- a/.gitignore +++ b/.gitignore @@ -362,7 +362,6 @@ lib/cpluff/stamp-h1 /system/libgif.dll /system/libssh2.dll /system/libssl32.dll -/system/hdhomerun.dll /system/ssh.dll /system/sqlite3.dll /system/libnfs.dll @@ -906,8 +905,6 @@ lib/cpluff/stamp-h1 /lib/libexif/Release (DLL) /lib/libexif/libexif.lib -/lib/libhdhomerun/Makefile - /lib/libsquish/Makefile /lib/libsquish/lib/squishd.lib /lib/libsquish/lib/squish.lib diff --git a/Kodi.xcodeproj/project.pbxproj b/Kodi.xcodeproj/project.pbxproj index 975f961d3e328..381683386ebc9 100644 --- a/Kodi.xcodeproj/project.pbxproj +++ b/Kodi.xcodeproj/project.pbxproj @@ -923,8 +923,6 @@ DF93D6B11444A8B1007C6459 /* UDFFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D6931444A8B0007C6459 /* UDFFile.cpp */; }; DF93D6B21444A8B1007C6459 /* UPnPFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D6951444A8B0007C6459 /* UPnPFile.cpp */; }; DF93D6B31444A8B1007C6459 /* ZipFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D6971444A8B0007C6459 /* ZipFile.cpp */; }; - DF93D7F21444B54A007C6459 /* HDHomeRunFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F01444B54A007C6459 /* HDHomeRunFile.cpp */; }; - DF93D7F61444B568007C6459 /* HDHomeRunDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F51444B568007C6459 /* HDHomeRunDirectory.cpp */; }; DF98D98C1434F47D00A6EBE1 /* SkinVariable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF98D98A1434F47D00A6EBE1 /* SkinVariable.cpp */; }; DF9A71EE1639C8F6005ECB2E /* HTTPFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF9A71EC1639C8F6005ECB2E /* HTTPFile.cpp */; }; DFA8157E16713B1200E4E597 /* WakeOnAccess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DFA8157C16713B1200E4E597 /* WakeOnAccess.cpp */; }; @@ -1265,8 +1263,6 @@ DFF0F1FE17528350002DA3A4 /* FileReaderFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D6731444A8B0007C6459 /* FileReaderFile.cpp */; }; DFF0F1FF17528350002DA3A4 /* FTPDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16E40D25F9FA00618676 /* FTPDirectory.cpp */; }; DFF0F20017528350002DA3A4 /* FTPParse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16E60D25F9FA00618676 /* FTPParse.cpp */; }; - DFF0F20317528350002DA3A4 /* HDHomeRunDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F51444B568007C6459 /* HDHomeRunDirectory.cpp */; }; - DFF0F20417528350002DA3A4 /* HDHomeRunFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F01444B54A007C6459 /* HDHomeRunFile.cpp */; }; DFF0F20717528350002DA3A4 /* HTTPDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F584E12D0F257C5100DB26A5 /* HTTPDirectory.cpp */; }; DFF0F20817528350002DA3A4 /* HTTPFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF9A71EC1639C8F6005ECB2E /* HTTPFile.cpp */; }; DFF0F20917528350002DA3A4 /* IDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16EC0D25F9FA00618676 /* IDirectory.cpp */; }; @@ -2447,8 +2443,6 @@ E4991267174E5D8F00741B6D /* FileReaderFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D6731444A8B0007C6459 /* FileReaderFile.cpp */; }; E4991268174E5D8F00741B6D /* FTPDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16E40D25F9FA00618676 /* FTPDirectory.cpp */; }; E4991269174E5D8F00741B6D /* FTPParse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16E60D25F9FA00618676 /* FTPParse.cpp */; }; - E499126C174E5D8F00741B6D /* HDHomeRunDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F51444B568007C6459 /* HDHomeRunDirectory.cpp */; }; - E499126D174E5D8F00741B6D /* HDHomeRunFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF93D7F01444B54A007C6459 /* HDHomeRunFile.cpp */; }; E4991270174E5D8F00741B6D /* HTTPDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F584E12D0F257C5100DB26A5 /* HTTPDirectory.cpp */; }; E4991271174E5D8F00741B6D /* HTTPFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DF9A71EC1639C8F6005ECB2E /* HTTPFile.cpp */; }; E4991272174E5D8F00741B6D /* IDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38E16EC0D25F9FA00618676 /* IDirectory.cpp */; }; @@ -4550,10 +4544,6 @@ DF93D6961444A8B0007C6459 /* UPnPFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UPnPFile.h; sourceTree = ""; }; DF93D6971444A8B0007C6459 /* ZipFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ZipFile.cpp; sourceTree = ""; }; DF93D6981444A8B0007C6459 /* ZipFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZipFile.h; sourceTree = ""; }; - DF93D7F01444B54A007C6459 /* HDHomeRunFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HDHomeRunFile.cpp; sourceTree = ""; }; - DF93D7F11444B54A007C6459 /* HDHomeRunFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HDHomeRunFile.h; sourceTree = ""; }; - DF93D7F41444B568007C6459 /* HDHomeRunDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HDHomeRunDirectory.h; sourceTree = ""; }; - DF93D7F51444B568007C6459 /* HDHomeRunDirectory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HDHomeRunDirectory.cpp; sourceTree = ""; }; DF98D98A1434F47D00A6EBE1 /* SkinVariable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SkinVariable.cpp; sourceTree = ""; }; DF98D98B1434F47D00A6EBE1 /* SkinVariable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SkinVariable.h; sourceTree = ""; }; DF9A71EC1639C8F6005ECB2E /* HTTPFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPFile.cpp; sourceTree = ""; }; @@ -5154,14 +5144,6 @@ E38E18580D25F9FA00618676 /* LangInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LangInfo.cpp; sourceTree = ""; }; E38E18590D25F9FA00618676 /* LangInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LangInfo.h; sourceTree = ""; }; E38E18830D25F9FA00618676 /* libexif.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libexif.h; sourceTree = ""; }; - E38E196E0D25F9FB00618676 /* hdhomerun.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun.h; sourceTree = ""; }; - E38E196F0D25F9FB00618676 /* hdhomerun_channelscan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_channelscan.h; sourceTree = ""; }; - E38E19700D25F9FB00618676 /* hdhomerun_control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_control.h; sourceTree = ""; }; - E38E19710D25F9FB00618676 /* hdhomerun_device.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_device.h; sourceTree = ""; }; - E38E19720D25F9FB00618676 /* hdhomerun_discover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_discover.h; sourceTree = ""; }; - E38E19730D25F9FB00618676 /* hdhomerun_os.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_os.h; sourceTree = ""; }; - E38E19740D25F9FB00618676 /* hdhomerun_pkt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_pkt.h; sourceTree = ""; }; - E38E19750D25F9FB00618676 /* hdhomerun_video.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hdhomerun_video.h; sourceTree = ""; }; E38E1AB80D25F9FB00618676 /* SConstruct */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SConstruct; sourceTree = ""; }; E38E1CD70D25F9FC00618676 /* dataset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dataset.cpp; sourceTree = ""; }; E38E1CD80D25F9FC00618676 /* dataset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dataset.h; sourceTree = ""; }; @@ -8705,10 +8687,6 @@ E38E16E50D25F9FA00618676 /* FTPDirectory.h */, E38E16E60D25F9FA00618676 /* FTPParse.cpp */, E38E16E70D25F9FA00618676 /* FTPParse.h */, - DF93D7F51444B568007C6459 /* HDHomeRunDirectory.cpp */, - DF93D7F41444B568007C6459 /* HDHomeRunDirectory.h */, - DF93D7F01444B54A007C6459 /* HDHomeRunFile.cpp */, - DF93D7F11444B54A007C6459 /* HDHomeRunFile.h */, F584E12D0F257C5100DB26A5 /* HTTPDirectory.cpp */, F584E12C0F257C5100DB26A5 /* HTTPDirectory.h */, DF9A71EC1639C8F6005ECB2E /* HTTPFile.cpp */, @@ -8928,7 +8906,6 @@ isa = PBXGroup; children = ( E38E18820D25F9FA00618676 /* libexif */, - E38E196D0D25F9FB00618676 /* libhdhomerun */, E38E1A550D25F9FB00618676 /* libUPnP */, E38E1CE40D25F9FC00618676 /* UnrarXLib */, ); @@ -8943,21 +8920,6 @@ path = libexif; sourceTree = ""; }; - E38E196D0D25F9FB00618676 /* libhdhomerun */ = { - isa = PBXGroup; - children = ( - E38E196E0D25F9FB00618676 /* hdhomerun.h */, - E38E196F0D25F9FB00618676 /* hdhomerun_channelscan.h */, - E38E19700D25F9FB00618676 /* hdhomerun_control.h */, - E38E19710D25F9FB00618676 /* hdhomerun_device.h */, - E38E19720D25F9FB00618676 /* hdhomerun_discover.h */, - E38E19730D25F9FB00618676 /* hdhomerun_os.h */, - E38E19740D25F9FB00618676 /* hdhomerun_pkt.h */, - E38E19750D25F9FB00618676 /* hdhomerun_video.h */, - ); - path = libhdhomerun; - sourceTree = ""; - }; E38E1A550D25F9FB00618676 /* libUPnP */ = { isa = PBXGroup; children = ( @@ -10797,8 +10759,6 @@ DF93D6B11444A8B1007C6459 /* UDFFile.cpp in Sources */, DF93D6B21444A8B1007C6459 /* UPnPFile.cpp in Sources */, DF93D6B31444A8B1007C6459 /* ZipFile.cpp in Sources */, - DF93D7F21444B54A007C6459 /* HDHomeRunFile.cpp in Sources */, - DF93D7F61444B568007C6459 /* HDHomeRunDirectory.cpp in Sources */, 7C1A85661520522500C63311 /* TextureCacheJob.cpp in Sources */, 7C1F6EBB13ECCFA7001726AB /* LibraryDirectory.cpp in Sources */, EC720A8F155091BB00FFD782 /* ilog.cpp in Sources */, @@ -11408,8 +11368,6 @@ DFF0F1FE17528350002DA3A4 /* FileReaderFile.cpp in Sources */, DFF0F1FF17528350002DA3A4 /* FTPDirectory.cpp in Sources */, DFF0F20017528350002DA3A4 /* FTPParse.cpp in Sources */, - DFF0F20317528350002DA3A4 /* HDHomeRunDirectory.cpp in Sources */, - DFF0F20417528350002DA3A4 /* HDHomeRunFile.cpp in Sources */, 395F6DE41A81FACF0088CC74 /* HTTPImageTransformationHandler.cpp in Sources */, DFF0F20717528350002DA3A4 /* HTTPDirectory.cpp in Sources */, DFF0F20817528350002DA3A4 /* HTTPFile.cpp in Sources */, @@ -12450,8 +12408,6 @@ E4991267174E5D8F00741B6D /* FileReaderFile.cpp in Sources */, E4991268174E5D8F00741B6D /* FTPDirectory.cpp in Sources */, E4991269174E5D8F00741B6D /* FTPParse.cpp in Sources */, - E499126C174E5D8F00741B6D /* HDHomeRunDirectory.cpp in Sources */, - E499126D174E5D8F00741B6D /* HDHomeRunFile.cpp in Sources */, E4991270174E5D8F00741B6D /* HTTPDirectory.cpp in Sources */, E4991271174E5D8F00741B6D /* HTTPFile.cpp in Sources */, DFC6F4C21AFF7E300039A7FA /* rfft.cpp in Sources */, diff --git a/Makefile.in b/Makefile.in index 392abf8315469..da3e94d36efb5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -189,7 +189,6 @@ endif LIB_DIRS=\ lib/cximage-6.0 \ lib/libexif \ - lib/libhdhomerun \ lib/cpluff \ lib/xbmc-dll-symbols @@ -405,15 +404,13 @@ else endif libexif: dllloader $(MAKE) -C lib/libexif -libhdhomerun: dllloader - $(MAKE) -C lib/libhdhomerun imagelib: dllloader $(MAKE) -C lib/cximage-6.0 codecs: dvdpcodecs dvdpextcodecs -libs: $(LIBSSE4) libhdhomerun imagelib libexif system/libcpluff-@ARCH@.so +libs: $(LIBSSE4) imagelib libexif system/libcpluff-@ARCH@.so externals: codecs libs visualizations screensavers libaddon diff --git a/configure.ac b/configure.ac index 4457e643c689c..2077dacfc1995 100644 --- a/configure.ac +++ b/configure.ac @@ -2478,7 +2478,6 @@ OUTPUT_FILES="Makefile \ xbmc/network/httprequesthandler/python/Makefile \ xbmc/network/upnp/Makefile \ lib/libexif/Makefile \ - lib/libhdhomerun/Makefile \ lib/cximage-6.0/Makefile \ lib/libUPnP/Makefile \ xbmc/DllPaths_generated.h \ diff --git a/lib/libhdhomerun/Makefile.in b/lib/libhdhomerun/Makefile.in deleted file mode 100644 index ce909c17cac48..0000000000000 --- a/lib/libhdhomerun/Makefile.in +++ /dev/null @@ -1,41 +0,0 @@ -ARCH=@ARCH@ - -OBJS += hdhomerun_pkt.o -OBJS += hdhomerun_debug.o -OBJS += hdhomerun_discover.o -OBJS += hdhomerun_channels.o -OBJS += hdhomerun_channelscan.o -OBJS += hdhomerun_control.o -OBJS += hdhomerun_video.o -OBJS += hdhomerun_device.o - -CFLAGS += -Wall -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -fPIC - -SLIBS += -lws2_32 -DEFINES += -D__MINGW__ - -SYSDIR=../../system -SO=hdhomerun-$(ARCH).so -SLIB=$(SYSDIR)/$(SO) - -$(SLIB): $(OBJS) -ifeq ($(findstring osx,$(ARCH)), osx) - $(CC) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \ - -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \ - @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) -else - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -shared -o $@ -Wl,--unresolved-symbols=ignore-all -lm \ - `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` \ - @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o -endif - -hdhomerun_dll : $(OBJS) - $(CC) $(CFLAGS) $(OBJS) $(SLIBS) -Wl,--out-implib,hdhomerun.lib -shared -o hdhomerun.dll - -hdhomerun_config hdhomerun_config.exe : $(OBJS) hdhomerun_config.o - $(CC) $(CFLAGS) $(OBJS) hdhomerun_config.o $(SLIBS) -lpthreadGC -liphlpapi -o $@ - -hdhomerun_mythconfig : $(LIBSRCS) hdhomerun_mythconfig.o - $(CC) $(CFLAGS) $(OBJS) hdhomerun_config.o $(SLIBS) -lpthreadGC -liphlpapi -lmysqlclient -o $@ - -include @abs_top_srcdir@/Makefile.include diff --git a/lib/libhdhomerun/Makefile.win32 b/lib/libhdhomerun/Makefile.win32 deleted file mode 100644 index ad1cd8cb5e7d2..0000000000000 --- a/lib/libhdhomerun/Makefile.win32 +++ /dev/null @@ -1,26 +0,0 @@ -ARCH=@ARCH@ - -OBJS += hdhomerun_pkt.o -OBJS += hdhomerun_debug.o -OBJS += hdhomerun_discover.o -OBJS += hdhomerun_channels.o -OBJS += hdhomerun_channelscan.o -OBJS += hdhomerun_control.o -OBJS += hdhomerun_video.o -OBJS += hdhomerun_device.o - -CFLAGS += -Wall -O2 -D__MINGW__ -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -CC=gcc - -SLIBS += -lws2_32 -liphlpapi - -SYSDIR=../../../system -DLL=hdhomerun.dll -SLIB=$(SYSDIR)/$(DLL) - -hdhomerun_dll : $(OBJS) - gcc $(OBJS) $(SLIBS) -Wl,--out-implib,hdhomerun.lib -shared -o $(SLIB) - -clean : - rm $(OBJS) - rm hdhomerun.lib \ No newline at end of file diff --git a/lib/libhdhomerun/README b/lib/libhdhomerun/README deleted file mode 100644 index f10520c0293fb..0000000000000 --- a/lib/libhdhomerun/README +++ /dev/null @@ -1,41 +0,0 @@ -/* - * README - * - * Copyright © 2005-2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -Top level include file: hdhomerun.h - -Top level API: hdhomerun_device. See hdhomerun_device.h for documentation. - -The hdhomerun_device API should be used rather than the low level control and video APIs required with previous versions. - -Additional libraries required: -- pthread -- iphlpapi (windows only) diff --git a/lib/libhdhomerun/hdhomerun.h b/lib/libhdhomerun/hdhomerun.h deleted file mode 100644 index 5174d33954eec..0000000000000 --- a/lib/libhdhomerun/hdhomerun.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * hdhomerun.h - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun_os.h" -#include "hdhomerun_types.h" -#include "hdhomerun_pkt.h" -#include "hdhomerun_debug.h" -#include "hdhomerun_discover.h" -#include "hdhomerun_control.h" -#include "hdhomerun_video.h" -#include "hdhomerun_channels.h" -#include "hdhomerun_channelscan.h" -#include "hdhomerun_device.h" diff --git a/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj b/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj deleted file mode 100644 index 9a9e26ae12bdb..0000000000000 --- a/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj +++ /dev/null @@ -1,140 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - libhdhomerun_dll - {1E2FB608-3DD2-4021-A598-90008FA6DE85} - hdhomerun - Win32Proj - - - - - DynamicLibrary - false - Unicode - true - - - DynamicLibrary - true - Unicode - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)libs\$(ProjectName)\$(Configuration)\ - $(SolutionDir)objs\$(ProjectName)\$(Configuration)\ - $(SolutionDir)libs\$(ProjectName)\$(Configuration)\ - $(SolutionDir)objs\$(ProjectName)\$(Configuration)\ - AllRules.ruleset - - - AllRules.ruleset - - - Build - Build - hdhomerun - hdhomerun - - - - _USRDLL;DLL_EXPORT;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - CompileAsCpp - Sync - - - ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies) - $(OutDir)$(TargetName)$(TargetExt) - $(OutDir)$(TargetName).pdb - - - $(OutDir)$(TargetName).lib - - - copy /B /Y "$(TargetPath)" "$(SolutionDir)..\..\system\$(TargetFileName)" - - - Copy Output - $(SolutionDir)..\..\system\$(TargetFileName) - $(TargetPath) - - - - - _USRDLL;DLL_EXPORT;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - Sync - - - CompileAsCpp - - - ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies) - $(OutDir)$(TargetName)$(TargetExt) - $(OutDir)$(TargetName).pdb - - - $(OutDir)$(TargetName).lib - - - copy /B /Y "$(TargetPath)" "$(SolutionDir)..\..\system\$(TargetFileName)" - - - Copy Output - $(SolutionDir)..\..\system\$(TargetFileName) - $(TargetPath) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj.filters b/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj.filters deleted file mode 100644 index ae402701f34fe..0000000000000 --- a/lib/libhdhomerun/hdhomerun/hdhomerun.vcxproj.filters +++ /dev/null @@ -1,83 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/lib/libhdhomerun/hdhomerun_channels.c b/lib/libhdhomerun/hdhomerun_channels.c deleted file mode 100644 index 38d72a38236b9..0000000000000 --- a/lib/libhdhomerun/hdhomerun_channels.c +++ /dev/null @@ -1,378 +0,0 @@ -/* - * hdhomerun_channels.c - * - * Copyright © 2007-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -#define FREQUENCY_RESOLUTION 62500 - -struct hdhomerun_channel_entry_t { - struct hdhomerun_channel_entry_t *next; - struct hdhomerun_channel_entry_t *prev; - uint32_t frequency; - uint8_t channel_number; - char name[16]; -}; - -struct hdhomerun_channel_list_t { - struct hdhomerun_channel_entry_t *head; - struct hdhomerun_channel_entry_t *tail; -}; - -struct hdhomerun_channelmap_range_t { - uint8_t channel_range_start; - uint8_t channel_range_end; - uint32_t frequency; - uint32_t spacing; -}; - -struct hdhomerun_channelmap_record_t { - const char *channelmap_prefix; - const char *channelmap; - const struct hdhomerun_channelmap_range_t *range_list; - const char *channelmap_scan_group; - const char *countrycodes; -}; - -/* AU antenna channels. Channels {0, 1, 2, 6, 7, 8, 9, 9A} are numbered {2, 3, 4, 5, 6, 7, 8, 9} by the HDHomeRun. */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_au_bcast[] = { - { 2, 2, 48500000, 7000000}, - { 3, 4, 59500000, 7000000}, - { 5, 12, 177500000, 7000000}, - { 28, 69, 529500000, 7000000}, - { 0, 0, 0, 0} -}; - -/* AU cable channels. TBD. */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_au_cable[] = { - { 0, 0, 0, 0} -}; - -/* EU antenna channels. */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_eu_bcast[] = { - { 2, 4, 50500000, 7000000}, - { 5, 12, 177500000, 7000000}, - { 21, 69, 474000000, 8000000}, - { 0, 0, 0, 0} -}; - -/* EU cable channels. Channels do not have simple numbers - the HDHomeRun uses its own numbering scheme (subject to change). */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_eu_cable[] = { - { 6, 7, 113000000, 8000000}, - { 9, 100, 138000000, 8000000}, - { 0, 0, 0, 0} -}; - -/* US antenna channels. */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_bcast[] = { - { 2, 4, 57000000, 6000000}, - { 5, 6, 79000000, 6000000}, - { 7, 13, 177000000, 6000000}, - { 14, 69, 473000000, 6000000}, - { 0, 0, 0, 0} -}; - -/* US cable channels. */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_cable[] = { - { 2, 4, 57000000, 6000000}, - { 5, 6, 79000000, 6000000}, - { 7, 13, 177000000, 6000000}, - { 14, 22, 123000000, 6000000}, - { 23, 94, 219000000, 6000000}, - { 95, 99, 93000000, 6000000}, - {100, 135, 651000000, 6000000}, - { 0, 0, 0, 0} -}; - -/* US cable channels (HRC). */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_hrc[] = { - { 2, 4, 55752700, 6000300}, - { 5, 6, 79753900, 6000300}, - { 7, 13, 175758700, 6000300}, - { 14, 22, 121756000, 6000300}, - { 23, 94, 217760800, 6000300}, - { 95, 99, 91754500, 6000300}, - {100, 135, 649782400, 6000300}, - { 0, 0, 0, 0} -}; - -/* US cable channels (IRC). */ -static const struct hdhomerun_channelmap_range_t hdhomerun_channelmap_range_us_irc[] = { - { 2, 4, 57012500, 6000000}, - { 5, 6, 81012500, 6000000}, - { 7, 13, 177012500, 6000000}, - { 14, 22, 123012500, 6000000}, - { 23, 41, 219012500, 6000000}, - { 42, 42, 333025000, 6000000}, - { 43, 94, 339012500, 6000000}, - { 95, 97, 93012500, 6000000}, - { 98, 99, 111025000, 6000000}, - {100, 135, 651012500, 6000000}, - { 0, 0, 0, 0} -}; - -static const struct hdhomerun_channelmap_record_t hdhomerun_channelmap_table[] = { - {"au", "au-bcast", hdhomerun_channelmap_range_au_bcast, "au-bcast", "AU"}, - {"au", "au-cable", hdhomerun_channelmap_range_au_cable, "au-cable", "AU"}, - {"eu", "eu-bcast", hdhomerun_channelmap_range_eu_bcast, "eu-bcast", "EU"}, - {"eu", "eu-cable", hdhomerun_channelmap_range_eu_cable, "eu-cable", "EU"}, - {"tw", "tw-bcast", hdhomerun_channelmap_range_us_bcast, "tw-bcast", "TW"}, - {"tw", "tw-cable", hdhomerun_channelmap_range_us_cable, "tw-cable", "TW"}, - {"us", "us-bcast", hdhomerun_channelmap_range_us_bcast, "us-bcast", "CA US"}, - {"us", "us-cable", hdhomerun_channelmap_range_us_cable, "us-cable us-hrc us-irc", "CA US"}, - {"us", "us-hrc", hdhomerun_channelmap_range_us_hrc , "us-cable us-hrc us-irc", "CA US"}, - {"us", "us-irc", hdhomerun_channelmap_range_us_irc, "us-cable us-hrc us-irc", "CA US"}, - {NULL, NULL, NULL, NULL, NULL} -}; - -const char *hdhomerun_channelmap_convert_countrycode_to_channelmap_prefix(const char *countrycode) -{ - const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table; - while (record->channelmap) { - if (strstr(record->countrycodes, countrycode)) { - return record->channelmap_prefix; - } - record++; - } - - return "eu"; -} - -const char *hdhomerun_channelmap_get_channelmap_scan_group(const char *channelmap) -{ - const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table; - while (record->channelmap) { - if (strstr(channelmap, record->channelmap)) { - return record->channelmap_scan_group; - } - record++; - } - - return NULL; -} - -uint8_t hdhomerun_channel_entry_channel_number(struct hdhomerun_channel_entry_t *entry) -{ - return entry->channel_number; -} - -uint32_t hdhomerun_channel_entry_frequency(struct hdhomerun_channel_entry_t *entry) -{ - return entry->frequency; -} - -const char *hdhomerun_channel_entry_name(struct hdhomerun_channel_entry_t *entry) -{ - return entry->name; -} - -struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(struct hdhomerun_channel_list_t *channel_list) -{ - return channel_list->head; -} - -struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(struct hdhomerun_channel_list_t *channel_list) -{ - return channel_list->tail; -} - -struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry) -{ - return entry->next; -} - -struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry) -{ - return entry->prev; -} - -uint32_t hdhomerun_channel_list_total_count(struct hdhomerun_channel_list_t *channel_list) -{ - uint32_t count = 0; - - struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list); - while (entry) { - count++; - entry = hdhomerun_channel_list_next(channel_list, entry); - } - - return count; -} - -uint32_t hdhomerun_channel_list_frequency_count(struct hdhomerun_channel_list_t *channel_list) -{ - uint32_t count = 0; - uint32_t last_frequency = 0; - - struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list); - while (entry) { - if (entry->frequency != last_frequency) { - last_frequency = entry->frequency; - count++; - } - - entry = hdhomerun_channel_list_next(channel_list, entry); - } - - return count; -} - -uint32_t hdhomerun_channel_frequency_truncate(uint32_t frequency) -{ - return (frequency / FREQUENCY_RESOLUTION) * FREQUENCY_RESOLUTION; -} - -uint32_t hdhomerun_channel_number_to_frequency(struct hdhomerun_channel_list_t *channel_list, uint8_t channel_number) -{ - struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list); - while (entry) { - if (entry->channel_number == channel_number) { - return entry->frequency; - } - - entry = hdhomerun_channel_list_next(channel_list, entry); - } - - return 0; -} - -uint8_t hdhomerun_channel_frequency_to_number(struct hdhomerun_channel_list_t *channel_list, uint32_t frequency) -{ - frequency = hdhomerun_channel_frequency_truncate(frequency); - - struct hdhomerun_channel_entry_t *entry = hdhomerun_channel_list_first(channel_list); - while (entry) { - if (entry->frequency == frequency) { - return entry->channel_number; - } - if (entry->frequency > frequency) { - return 0; - } - - entry = hdhomerun_channel_list_next(channel_list, entry); - } - - return 0; -} - -static void hdhomerun_channel_list_build_insert(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry) -{ - struct hdhomerun_channel_entry_t *prev = NULL; - struct hdhomerun_channel_entry_t *next = channel_list->head; - - while (next) { - if (next->frequency > entry->frequency) { - break; - } - - prev = next; - next = next->next; - } - - entry->prev = prev; - entry->next = next; - - if (prev) { - prev->next = entry; - } else { - channel_list->head = entry; - } - - if (next) { - next->prev = entry; - } else { - channel_list->tail = entry; - } -} - -static void hdhomerun_channel_list_build_range(struct hdhomerun_channel_list_t *channel_list, const char *channelmap, const struct hdhomerun_channelmap_range_t *range) -{ - uint8_t channel_number; - for (channel_number = range->channel_range_start; channel_number <= range->channel_range_end; channel_number++) { - struct hdhomerun_channel_entry_t *entry = (struct hdhomerun_channel_entry_t *)calloc(1, sizeof(struct hdhomerun_channel_entry_t)); - if (!entry) { - return; - } - - entry->channel_number = channel_number; - entry->frequency = range->frequency + ((uint32_t)(channel_number - range->channel_range_start) * range->spacing); - entry->frequency = hdhomerun_channel_frequency_truncate(entry->frequency); - sprintf(entry->name, "%s:%u", channelmap, entry->channel_number); - - hdhomerun_channel_list_build_insert(channel_list, entry); - } -} - -static void hdhomerun_channel_list_build_ranges(struct hdhomerun_channel_list_t *channel_list, const struct hdhomerun_channelmap_record_t *record) -{ - const struct hdhomerun_channelmap_range_t *range = record->range_list; - while (range->frequency) { - hdhomerun_channel_list_build_range(channel_list, record->channelmap, range); - range++; - } -} - -void hdhomerun_channel_list_destroy(struct hdhomerun_channel_list_t *channel_list) -{ - while (channel_list->head) { - struct hdhomerun_channel_entry_t *entry = channel_list->head; - channel_list->head = entry->next; - free(entry); - } - - free(channel_list); -} - -struct hdhomerun_channel_list_t *hdhomerun_channel_list_create(const char *channelmap) -{ - struct hdhomerun_channel_list_t *channel_list = (struct hdhomerun_channel_list_t *)calloc(1, sizeof(struct hdhomerun_channel_list_t)); - if (!channel_list) { - return NULL; - } - - const struct hdhomerun_channelmap_record_t *record = hdhomerun_channelmap_table; - while (record->channelmap) { - if (!strstr(channelmap, record->channelmap)) { - record++; - continue; - } - - hdhomerun_channel_list_build_ranges(channel_list, record); - record++; - } - - if (!channel_list->head) { - free(channel_list); - return NULL; - } - - return channel_list; -} diff --git a/lib/libhdhomerun/hdhomerun_channels.h b/lib/libhdhomerun/hdhomerun_channels.h deleted file mode 100644 index 7f602a28db6fc..0000000000000 --- a/lib/libhdhomerun/hdhomerun_channels.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * hdhomerun_channels.h - * - * Copyright © 2007-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_channel_entry_t; -struct hdhomerun_channel_list_t; - -extern LIBTYPE const char *hdhomerun_channelmap_convert_countrycode_to_channelmap_prefix(const char *countrycode); -extern LIBTYPE const char *hdhomerun_channelmap_get_channelmap_scan_group(const char *channelmap); - -extern LIBTYPE uint8_t hdhomerun_channel_entry_channel_number(struct hdhomerun_channel_entry_t *entry); -extern LIBTYPE uint32_t hdhomerun_channel_entry_frequency(struct hdhomerun_channel_entry_t *entry); -extern LIBTYPE const char *hdhomerun_channel_entry_name(struct hdhomerun_channel_entry_t *entry); - -extern LIBTYPE struct hdhomerun_channel_list_t *hdhomerun_channel_list_create(const char *channelmap); -extern LIBTYPE void hdhomerun_channel_list_destroy(struct hdhomerun_channel_list_t *channel_list); - -extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_first(struct hdhomerun_channel_list_t *channel_list); -extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_last(struct hdhomerun_channel_list_t *channel_list); -extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_next(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry); -extern LIBTYPE struct hdhomerun_channel_entry_t *hdhomerun_channel_list_prev(struct hdhomerun_channel_list_t *channel_list, struct hdhomerun_channel_entry_t *entry); -extern LIBTYPE uint32_t hdhomerun_channel_list_total_count(struct hdhomerun_channel_list_t *channel_list); -extern LIBTYPE uint32_t hdhomerun_channel_list_frequency_count(struct hdhomerun_channel_list_t *channel_list); - -extern LIBTYPE uint32_t hdhomerun_channel_frequency_truncate(uint32_t frequency); -extern LIBTYPE uint32_t hdhomerun_channel_number_to_frequency(struct hdhomerun_channel_list_t *channel_list, uint8_t channel_number); -extern LIBTYPE uint8_t hdhomerun_channel_frequency_to_number(struct hdhomerun_channel_list_t *channel_list, uint32_t frequency); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_channelscan.c b/lib/libhdhomerun/hdhomerun_channelscan.c deleted file mode 100644 index f661bc4a82d77..0000000000000 --- a/lib/libhdhomerun/hdhomerun_channelscan.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * hdhomerun_channelscan.c - * - * Copyright © 2007-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -struct hdhomerun_channelscan_t { - struct hdhomerun_device_t *hd; - uint32_t scanned_channels; - struct hdhomerun_channel_list_t *channel_list; - struct hdhomerun_channel_entry_t *next_channel; -}; - -struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, const char *channelmap) -{ - struct hdhomerun_channelscan_t *scan = (struct hdhomerun_channelscan_t *)calloc(1, sizeof(struct hdhomerun_channelscan_t)); - if (!scan) { - return NULL; - } - - scan->hd = hd; - - scan->channel_list = hdhomerun_channel_list_create(channelmap); - if (!scan->channel_list) { - free(scan); - return NULL; - } - - scan->next_channel = hdhomerun_channel_list_last(scan->channel_list); - return scan; -} - -void channelscan_destroy(struct hdhomerun_channelscan_t *scan) -{ - free(scan); -} - -static int channelscan_find_lock(struct hdhomerun_channelscan_t *scan, uint32_t frequency, struct hdhomerun_channelscan_result_t *result) -{ - /* Set channel. */ - char channel_str[64]; - sprintf(channel_str, "auto:%ld", (unsigned long)frequency); - - int ret = hdhomerun_device_set_tuner_channel(scan->hd, channel_str); - if (ret <= 0) { - return ret; - } - - /* Wait for lock. */ - ret = hdhomerun_device_wait_for_lock(scan->hd, &result->status); - if (ret <= 0) { - return ret; - } - if (!result->status.lock_supported) { - return 1; - } - - /* Wait for symbol quality = 100%. */ - uint64_t timeout = getcurrenttime() + 5000; - while (1) { - ret = hdhomerun_device_get_tuner_status(scan->hd, NULL, &result->status); - if (ret <= 0) { - return ret; - } - - if (result->status.symbol_error_quality == 100) { - return 1; - } - - if (getcurrenttime() >= timeout) { - return 1; - } - - msleep(250); - } -} - -static void channelscan_extract_name(struct hdhomerun_channelscan_program_t *program, const char *line) -{ - /* Find start of name. */ - const char *start = strchr(line, ' '); - if (!start) { - return; - } - start++; - - start = strchr(start, ' '); - if (!start) { - return; - } - start++; - - /* Find end of name. */ - const char *end = strstr(start, " ("); - if (!end) { - end = strchr(line, 0); - } - - if (end <= start) { - return; - } - - /* Extract name. */ - size_t length = (size_t)(end - start); - if (length > sizeof(program->name) - 1) { - length = sizeof(program->name) - 1; - } - - strncpy(program->name, start, length); - program->name[length] = 0; -} - -static int channelscan_detect_programs(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result, bool_t *pchanged, bool_t *pincomplete) -{ - *pchanged = FALSE; - *pincomplete = FALSE; - - char *streaminfo; - int ret = hdhomerun_device_get_tuner_streaminfo(scan->hd, &streaminfo); - if (ret <= 0) { - return ret; - } - - char *line = streaminfo; - int program_count = 0; - - while (1) { - char *end = strchr(line, '\n'); - if (!end) { - break; - } - - *end = 0; - - unsigned long pat_crc; - if (sscanf(line, "crc=0x%lx", &pat_crc) == 1) { - result->pat_crc = pat_crc; - continue; - } - - struct hdhomerun_channelscan_program_t program; - memset(&program, 0, sizeof(program)); - - strncpy(program.program_str, line, sizeof(program.program_str)); - program.program_str[sizeof(program.program_str) - 1] = 0; - - unsigned int program_number; - unsigned int virtual_major, virtual_minor; - if (sscanf(line, "%u: %u.%u", &program_number, &virtual_major, &virtual_minor) != 3) { - if (sscanf(line, "%u: %u", &program_number, &virtual_major) != 2) { - continue; - } - virtual_minor = 0; - } - - program.program_number = program_number; - program.virtual_major = virtual_major; - program.virtual_minor = virtual_minor; - - channelscan_extract_name(&program, line); - - if (strstr(line, "(control)")) { - program.type = HDHOMERUN_CHANNELSCAN_PROGRAM_CONTROL; - } else if (strstr(line, "(encrypted)")) { - program.type = HDHOMERUN_CHANNELSCAN_PROGRAM_ENCRYPTED; - } else if (strstr(line, "(no data)")) { - program.type = HDHOMERUN_CHANNELSCAN_PROGRAM_NODATA; - *pincomplete = TRUE; - } else { - program.type = HDHOMERUN_CHANNELSCAN_PROGRAM_NORMAL; - if ((program.virtual_major == 0) || (program.name[0] == 0)) { - *pincomplete = TRUE; - } - } - - if (memcmp(&result->programs[program_count], &program, sizeof(program)) != 0) { - memcpy(&result->programs[program_count], &program, sizeof(program)); - *pchanged = TRUE; - } - - program_count++; - if (program_count >= HDHOMERUN_CHANNELSCAN_MAX_PROGRAM_COUNT) { - break; - } - - line = end + 1; - } - - if (program_count == 0) { - *pincomplete = TRUE; - } - if (result->program_count != program_count) { - result->program_count = program_count; - *pchanged = TRUE; - } - - return 1; -} - -int channelscan_advance(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result) -{ - memset(result, 0, sizeof(struct hdhomerun_channelscan_result_t)); - - struct hdhomerun_channel_entry_t *entry = scan->next_channel; - if (!entry) { - return 0; - } - - /* Combine channels with same frequency. */ - result->frequency = hdhomerun_channel_entry_frequency(entry); - strncpy(result->channel_str, hdhomerun_channel_entry_name(entry), sizeof(result->channel_str) - 1); - result->channel_str[sizeof(result->channel_str) - 1] = 0; - - while (1) { - entry = hdhomerun_channel_list_prev(scan->channel_list, entry); - if (!entry) { - scan->next_channel = NULL; - break; - } - - if (hdhomerun_channel_entry_frequency(entry) != result->frequency) { - scan->next_channel = entry; - break; - } - - char *ptr = strchr(result->channel_str, 0); - sprintf(ptr, ", %s", hdhomerun_channel_entry_name(entry)); - } - - return 1; -} - -int channelscan_detect(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result) -{ - scan->scanned_channels++; - - /* Find lock. */ - int ret = channelscan_find_lock(scan, result->frequency, result); - if (ret <= 0) { - return ret; - } - if (!result->status.lock_supported) { - return 1; - } - - /* Detect programs. */ - result->program_count = 0; - - uint64_t timeout = getcurrenttime() + 10000; - uint64_t complete_time = getcurrenttime() + 2000; - while (1) { - bool_t changed, incomplete; - ret = channelscan_detect_programs(scan, result, &changed, &incomplete); - if (ret <= 0) { - return ret; - } - - if (changed) { - complete_time = getcurrenttime() + 2000; - } - - if (!incomplete && (getcurrenttime() >= complete_time)) { - return 1; - } - - if (getcurrenttime() >= timeout) { - return 1; - } - - msleep(250); - } -} - -uint8_t channelscan_get_progress(struct hdhomerun_channelscan_t *scan) -{ - struct hdhomerun_channel_entry_t *entry = scan->next_channel; - if (!entry) { - return 100; - } - - uint32_t channels_remaining = 1; - uint32_t frequency = hdhomerun_channel_entry_frequency(entry); - - while (1) { - entry = hdhomerun_channel_list_prev(scan->channel_list, entry); - if (!entry) { - break; - } - - if (hdhomerun_channel_entry_frequency(entry) != frequency) { - channels_remaining++; - frequency = hdhomerun_channel_entry_frequency(entry); - } - } - - return scan->scanned_channels * 100 / (scan->scanned_channels + channels_remaining); -} diff --git a/lib/libhdhomerun/hdhomerun_channelscan.h b/lib/libhdhomerun/hdhomerun_channelscan.h deleted file mode 100644 index 3c853d5fac226..0000000000000 --- a/lib/libhdhomerun/hdhomerun_channelscan.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * hdhomerun_channelscan.h - * - * Copyright © 2007-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define HDHOMERUN_CHANNELSCAN_PROGRAM_NORMAL 0 -#define HDHOMERUN_CHANNELSCAN_PROGRAM_NODATA 1 -#define HDHOMERUN_CHANNELSCAN_PROGRAM_CONTROL 2 -#define HDHOMERUN_CHANNELSCAN_PROGRAM_ENCRYPTED 3 - -struct hdhomerun_channelscan_t; - -extern LIBTYPE struct hdhomerun_channelscan_t *channelscan_create(struct hdhomerun_device_t *hd, const char *channelmap); -extern LIBTYPE void channelscan_destroy(struct hdhomerun_channelscan_t *scan); - -extern LIBTYPE int channelscan_advance(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result); -extern LIBTYPE int channelscan_detect(struct hdhomerun_channelscan_t *scan, struct hdhomerun_channelscan_result_t *result); -extern LIBTYPE uint8_t channelscan_get_progress(struct hdhomerun_channelscan_t *scan); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_config.c b/lib/libhdhomerun/hdhomerun_config.c deleted file mode 100644 index fc65078167088..0000000000000 --- a/lib/libhdhomerun/hdhomerun_config.c +++ /dev/null @@ -1,636 +0,0 @@ -/* - * hdhomerun_config.c - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -/* - * The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing. - * Attempting to restore on exit fails to restore if the program is terminated by the user. - * Solution - set the output format each printf. - */ -#if defined(__WINDOWS__) -#define printf console_printf -#define vprintf console_vprintf -#endif - -static const char *appname; - -struct hdhomerun_device_t *hd; - -static int help(void) -{ - printf("Usage:\n"); - printf("\t%s discover\n", appname); - printf("\t%s get help\n", appname); - printf("\t%s get \n", appname); - printf("\t%s set \n", appname); - printf("\t%s scan []\n", appname); - printf("\t%s save \n", appname); - printf("\t%s upgrade \n", appname); - return -1; -} - -static void extract_appname(const char *argv0) -{ - const char *ptr = strrchr(argv0, '/'); - if (ptr) { - argv0 = ptr + 1; - } - ptr = strrchr(argv0, '\\'); - if (ptr) { - argv0 = ptr + 1; - } - appname = argv0; -} - -static bool_t contains(const char *arg, const char *cmpstr) -{ - if (strcmp(arg, cmpstr) == 0) { - return TRUE; - } - - if (*arg++ != '-') { - return FALSE; - } - if (*arg++ != '-') { - return FALSE; - } - if (strcmp(arg, cmpstr) == 0) { - return TRUE; - } - - return FALSE; -} - -static uint32_t parse_ip_addr(const char *str) -{ - unsigned long a[4]; - if (sscanf(str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) != 4) { - return 0; - } - - return (uint32_t)((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0)); -} - -static int discover_print(char *target_ip_str) -{ - uint32_t target_ip = 0; - if (target_ip_str) { - target_ip = parse_ip_addr(target_ip_str); - if (target_ip == 0) { - fprintf(stderr, "invalid ip address: %s\n", target_ip_str); - return -1; - } - } - - struct hdhomerun_discover_device_t result_list[64]; - int count = hdhomerun_discover_find_devices_custom(target_ip, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, result_list, 64); - if (count < 0) { - fprintf(stderr, "error sending discover request\n"); - return -1; - } - if (count == 0) { - printf("no devices found\n"); - return 0; - } - - int index; - for (index = 0; index < count; index++) { - struct hdhomerun_discover_device_t *result = &result_list[index]; - printf("hdhomerun device %08lX found at %u.%u.%u.%u\n", - (unsigned long)result->device_id, - (unsigned int)(result->ip_addr >> 24) & 0x0FF, (unsigned int)(result->ip_addr >> 16) & 0x0FF, - (unsigned int)(result->ip_addr >> 8) & 0x0FF, (unsigned int)(result->ip_addr >> 0) & 0x0FF - ); - } - - return count; -} - -static int cmd_get(const char *item) -{ - char *ret_value; - char *ret_error; - if (hdhomerun_device_get_var(hd, item, &ret_value, &ret_error) < 0) { - fprintf(stderr, "communication error sending request to hdhomerun device\n"); - return -1; - } - - if (ret_error) { - printf("%s\n", ret_error); - return 0; - } - - printf("%s\n", ret_value); - return 1; -} - -static int cmd_set_internal(const char *item, const char *value) -{ - char *ret_error; - if (hdhomerun_device_set_var(hd, item, value, NULL, &ret_error) < 0) { - fprintf(stderr, "communication error sending request to hdhomerun device\n"); - return -1; - } - - if (ret_error) { - printf("%s\n", ret_error); - return 0; - } - - return 1; -} - -static int cmd_set(const char *item, const char *value) -{ - if (strcmp(value, "-") == 0) { - char *buffer = NULL; - size_t pos = 0; - - while (1) { - buffer = (char *)realloc(buffer, pos + 1024); - if (!buffer) { - fprintf(stderr, "out of memory\n"); - return -1; - } - - size_t size = fread(buffer + pos, 1, 1024, stdin); - pos += size; - - if (size < 1024) { - break; - } - } - - buffer[pos] = 0; - - int ret = cmd_set_internal(item, buffer); - - free(buffer); - return ret; - } - - return cmd_set_internal(item, value); -} - -static void cmd_scan_printf(FILE *fp, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - if (fp) { - va_list apc; - va_copy(apc, ap); - - vfprintf(fp, fmt, apc); - fflush(fp); - - va_end(apc); - } - - vprintf(fmt, ap); - fflush(stdout); - - va_end(ap); -} - -static int cmd_scan(const char *tuner_str, const char *filename) -{ - if (hdhomerun_device_set_tuner_from_str(hd, tuner_str) <= 0) { - fprintf(stderr, "invalid tuner number\n"); - return -1; - } - - char *channelmap; - if (hdhomerun_device_get_tuner_channelmap(hd, &channelmap) <= 0) { - fprintf(stderr, "failed to query channelmap from device\n"); - return -1; - } - - const char *channelmap_scan_group = hdhomerun_channelmap_get_channelmap_scan_group(channelmap); - if (!channelmap_scan_group) { - fprintf(stderr, "unknown channelmap '%s'\n", channelmap); - return -1; - } - - if (hdhomerun_device_channelscan_init(hd, channelmap_scan_group) <= 0) { - fprintf(stderr, "failed to initialize channel scan\n"); - return -1; - } - - FILE *fp = NULL; - if (filename) { - fp = fopen(filename, "w"); - if (!fp) { - fprintf(stderr, "unable to create file: %s\n", filename); - return -1; - } - } - - int ret; - while (1) { - struct hdhomerun_channelscan_result_t result; - ret = hdhomerun_device_channelscan_advance(hd, &result); - if (ret <= 0) { - break; - } - - cmd_scan_printf(fp, "SCANNING: %lu (%s)\n", - result.frequency, result.channel_str - ); - - ret = hdhomerun_device_channelscan_detect(hd, &result); - if (ret <= 0) { - break; - } - - cmd_scan_printf(fp, "LOCK: %s (ss=%u snq=%u seq=%u)\n", - result.status.lock_str, result.status.signal_strength, - result.status.signal_to_noise_quality, result.status.symbol_error_quality - ); - - int i; - for (i = 0; i < result.program_count; i++) { - struct hdhomerun_channelscan_program_t *program = &result.programs[i]; - cmd_scan_printf(fp, "PROGRAM %s\n", program->program_str); - } - } - - if (fp) { - fclose(fp); - } - if (ret < 0) { - fprintf(stderr, "communication error sending request to hdhomerun device\n"); - } - return ret; -} - -static bool_t cmd_saving = FALSE; - -static void cmd_save_abort(int arg) -{ - cmd_saving = FALSE; -} - -static int cmd_save(const char *tuner_str, const char *filename) -{ - if (hdhomerun_device_set_tuner_from_str(hd, tuner_str) <= 0) { - fprintf(stderr, "invalid tuner number\n"); - return -1; - } - - FILE *fp; - if (strcmp(filename, "null") == 0) { - fp = NULL; - } else if (strcmp(filename, "-") == 0) { - fp = stdout; - } else { - fp = fopen(filename, "wb"); - if (!fp) { - fprintf(stderr, "unable to create file %s\n", filename); - return -1; - } - } - - int ret = hdhomerun_device_stream_start(hd); - if (ret <= 0) { - fprintf(stderr, "unable to start stream\n"); - return ret; - } - - signal(SIGINT, cmd_save_abort); - signal(SIGPIPE, cmd_save_abort); - - struct hdhomerun_video_stats_t stats_old, stats_cur; - hdhomerun_device_get_video_stats(hd, &stats_old); - - uint64_t next_progress = getcurrenttime() + 1000; - - cmd_saving = TRUE; - while (cmd_saving) { - uint64_t loop_start_time = getcurrenttime(); - - size_t actual_size; - uint8_t *ptr = hdhomerun_device_stream_recv(hd, VIDEO_DATA_BUFFER_SIZE_1S, &actual_size); - if (!ptr) { - msleep(64); - continue; - } - - if (fp) { - if (fwrite(ptr, 1, actual_size, fp) != actual_size) { - fprintf(stderr, "error writing output\n"); - return -1; - } - } - - if (loop_start_time >= next_progress) { - next_progress += 1000; - if (loop_start_time >= next_progress) { - next_progress = loop_start_time + 1000; - } - - hdhomerun_device_get_video_stats(hd, &stats_cur); - - if (stats_cur.overflow_error_count > stats_old.overflow_error_count) { - fprintf(stderr, "o"); - } else if (stats_cur.network_error_count > stats_old.network_error_count) { - fprintf(stderr, "n"); - } else if (stats_cur.transport_error_count > stats_old.transport_error_count) { - fprintf(stderr, "t"); - } else if (stats_cur.sequence_error_count > stats_old.sequence_error_count) { - fprintf(stderr, "s"); - } else { - fprintf(stderr, "."); - } - - stats_old = stats_cur; - fflush(stderr); - } - - int32_t delay = 64 - (int32_t)(getcurrenttime() - loop_start_time); - if (delay <= 0) { - continue; - } - - msleep(delay); - } - - if (fp) { - fclose(fp); - } - - hdhomerun_device_stream_stop(hd); - hdhomerun_device_get_video_stats(hd, &stats_cur); - - fprintf(stderr, "\n"); - fprintf(stderr, "-- Video statistics --\n"); - fprintf(stderr, "%u packets received, %u overflow errors, %u network errors, %u transport errors, %u sequence errors\n", - (unsigned int)stats_cur.packet_count, - (unsigned int)stats_cur.overflow_error_count, - (unsigned int)stats_cur.network_error_count, - (unsigned int)stats_cur.transport_error_count, - (unsigned int)stats_cur.sequence_error_count); - - return 0; -} - -static int cmd_upgrade(const char *filename) -{ - FILE *fp = fopen(filename, "rb"); - if (!fp) { - fprintf(stderr, "unable to open file %s\n", filename); - return -1; - } - - printf("uploading firmware...\n"); - if (hdhomerun_device_upgrade(hd, fp) <= 0) { - fprintf(stderr, "error sending upgrade file to hdhomerun device\n"); - fclose(fp); - return -1; - } - sleep(2); - - printf("upgrading firmware...\n"); - sleep(8); - - printf("rebooting...\n"); - int count = 0; - char *version_str; - while (1) { - if (hdhomerun_device_get_version(hd, &version_str, NULL) >= 0) { - break; - } - - count++; - if (count > 30) { - fprintf(stderr, "error finding device after firmware upgrade\n"); - fclose(fp); - return -1; - } - - sleep(1); - } - - printf("upgrade complete - now running firmware %s\n", version_str); - return 0; -} - -static int cmd_execute(void) -{ - char *ret_value; - char *ret_error; - if (hdhomerun_device_get_var(hd, "/sys/boot", &ret_value, &ret_error) < 0) { - fprintf(stderr, "communication error sending request to hdhomerun device\n"); - return -1; - } - - if (ret_error) { - printf("%s\n", ret_error); - return 0; - } - - char *end = ret_value + strlen(ret_value); - char *pos = ret_value; - - while (1) { - if (pos >= end) { - break; - } - - char *eol_r = strchr(pos, '\r'); - if (!eol_r) { - eol_r = end; - } - - char *eol_n = strchr(pos, '\n'); - if (!eol_n) { - eol_n = end; - } - - char *eol = min(eol_r, eol_n); - - char *sep = strchr(pos, ' '); - if (!sep || sep > eol) { - pos = eol + 1; - continue; - } - - *sep = 0; - *eol = 0; - - char *item = pos; - char *value = sep + 1; - - printf("set %s \"%s\"\n", item, value); - - cmd_set_internal(item, value); - - pos = eol + 1; - } - - return 1; -} - -static int main_cmd(int argc, char *argv[]) -{ - if (argc < 1) { - return help(); - } - - char *cmd = *argv++; argc--; - - if (contains(cmd, "key")) { - if (argc < 2) { - return help(); - } - uint32_t lockkey = strtoul(argv[0], NULL, 0); - hdhomerun_device_tuner_lockkey_use_value(hd, lockkey); - - cmd = argv[1]; - argv+=2; argc-=2; - } - - if (contains(cmd, "get")) { - if (argc < 1) { - return help(); - } - return cmd_get(argv[0]); - } - - if (contains(cmd, "set")) { - if (argc < 2) { - return help(); - } - return cmd_set(argv[0], argv[1]); - } - - if (contains(cmd, "scan")) { - if (argc < 1) { - return help(); - } - if (argc < 2) { - return cmd_scan(argv[0], NULL); - } else { - return cmd_scan(argv[0], argv[1]); - } - } - - if (contains(cmd, "save")) { - if (argc < 2) { - return help(); - } - return cmd_save(argv[0], argv[1]); - } - - if (contains(cmd, "upgrade")) { - if (argc < 1) { - return help(); - } - return cmd_upgrade(argv[0]); - } - - if (contains(cmd, "execute")) { - return cmd_execute(); - } - - return help(); -} - -static int main_internal(int argc, char *argv[]) -{ -#if defined(__WINDOWS__) - /* Initialize network socket support. */ - WORD wVersionRequested = MAKEWORD(2, 0); - WSADATA wsaData; - WSAStartup(wVersionRequested, &wsaData); -#endif - - extract_appname(argv[0]); - argv++; - argc--; - - if (argc == 0) { - return help(); - } - - char *id_str = *argv++; argc--; - if (contains(id_str, "help")) { - return help(); - } - if (contains(id_str, "discover")) { - if (argc < 1) { - return discover_print(NULL); - } else { - return discover_print(argv[0]); - } - } - - /* Device object. */ - hd = hdhomerun_device_create_from_str(id_str, NULL); - if (!hd) { - fprintf(stderr, "invalid device id: %s\n", id_str); - return -1; - } - - /* Device ID check. */ - uint32_t device_id_requested = hdhomerun_device_get_device_id_requested(hd); - if (!hdhomerun_discover_validate_device_id(device_id_requested)) { - fprintf(stderr, "invalid device id: %08lX\n", (unsigned long)device_id_requested); - } - - /* Connect to device and check model. */ - const char *model = hdhomerun_device_get_model_str(hd); - if (!model) { - fprintf(stderr, "unable to connect to device\n"); - hdhomerun_device_destroy(hd); - return -1; - } - - /* Command. */ - int ret = main_cmd(argc, argv); - - /* Cleanup. */ - hdhomerun_device_destroy(hd); - - /* Complete. */ - return ret; -} - -int main(int argc, char *argv[]) -{ - int ret = main_internal(argc, argv); - if (ret <= 0) { - return 1; - } - return 0; -} diff --git a/lib/libhdhomerun/hdhomerun_control.c b/lib/libhdhomerun/hdhomerun_control.c deleted file mode 100644 index 8d76a2375602b..0000000000000 --- a/lib/libhdhomerun/hdhomerun_control.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * hdhomerun_control.c - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -#define HDHOMERUN_CONTROL_SEND_TIMEOUT 5000 -#define HDHOMERUN_CONTROL_RECV_TIMEOUT 5000 -#define HDHOMERUN_CONTROL_UPGRADE_TIMEOUT 20000 - -struct hdhomerun_control_sock_t { - uint32_t desired_device_id; - uint32_t desired_device_ip; - uint32_t actual_device_id; - uint32_t actual_device_ip; - int sock; - struct hdhomerun_debug_t *dbg; - struct hdhomerun_pkt_t tx_pkt; - struct hdhomerun_pkt_t rx_pkt; -}; - -static void hdhomerun_control_close_sock(struct hdhomerun_control_sock_t *cs) -{ - if (cs->sock == -1) { - return; - } - - close(cs->sock); - cs->sock = -1; -} - -void hdhomerun_control_set_device(struct hdhomerun_control_sock_t *cs, uint32_t device_id, uint32_t device_ip) -{ - hdhomerun_control_close_sock(cs); - - cs->desired_device_id = device_id; - cs->desired_device_ip = device_ip; - cs->actual_device_id = 0; - cs->actual_device_ip = 0; -} - -struct hdhomerun_control_sock_t *hdhomerun_control_create(uint32_t device_id, uint32_t device_ip, struct hdhomerun_debug_t *dbg) -{ - struct hdhomerun_control_sock_t *cs = (struct hdhomerun_control_sock_t *)calloc(1, sizeof(struct hdhomerun_control_sock_t)); - if (!cs) { - hdhomerun_debug_printf(dbg, "hdhomerun_control_create: failed to allocate control object\n"); - return NULL; - } - - cs->dbg = dbg; - cs->sock = -1; - hdhomerun_control_set_device(cs, device_id, device_ip); - - return cs; -} - -void hdhomerun_control_destroy(struct hdhomerun_control_sock_t *cs) -{ - hdhomerun_control_close_sock(cs); - free(cs); -} - -static bool_t hdhomerun_control_connect_sock(struct hdhomerun_control_sock_t *cs) -{ - if (cs->sock != -1) { - return TRUE; - } - - if ((cs->desired_device_id == 0) && (cs->desired_device_ip == 0)) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_connect_sock: no device specified\n"); - return FALSE; - } - - /* Find device. */ - struct hdhomerun_discover_device_t result; - if (hdhomerun_discover_find_devices_custom(cs->desired_device_ip, HDHOMERUN_DEVICE_TYPE_WILDCARD, cs->desired_device_id, &result, 1) <= 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_connect_sock: device not found\n"); - return FALSE; - } - cs->actual_device_ip = result.ip_addr; - cs->actual_device_id = result.device_id; - - /* Create socket. */ - cs->sock = (int)socket(AF_INET, SOCK_STREAM, 0); - if (cs->sock == -1) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_connect_sock: failed to create socket (%d)\n", sock_getlasterror); - return FALSE; - } - - /* Set timeouts. */ - setsocktimeout(cs->sock, SOL_SOCKET, SO_SNDTIMEO, HDHOMERUN_CONTROL_SEND_TIMEOUT); - setsocktimeout(cs->sock, SOL_SOCKET, SO_RCVTIMEO, HDHOMERUN_CONTROL_RECV_TIMEOUT); - - /* Initiate connection. */ - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(cs->actual_device_ip); - sock_addr.sin_port = htons(HDHOMERUN_CONTROL_TCP_PORT); - if (connect(cs->sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_connect_sock: failed to connect (%d)\n", sock_getlasterror); - hdhomerun_control_close_sock(cs); - return FALSE; - } - - /* Success. */ - return TRUE; -} - -uint32_t hdhomerun_control_get_device_id(struct hdhomerun_control_sock_t *cs) -{ - if (!hdhomerun_control_connect_sock(cs)) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_device_id: connect failed\n"); - return 0; - } - - return cs->actual_device_id; -} - -uint32_t hdhomerun_control_get_device_ip(struct hdhomerun_control_sock_t *cs) -{ - if (!hdhomerun_control_connect_sock(cs)) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_device_ip: connect failed\n"); - return 0; - } - - return cs->actual_device_ip; -} - -uint32_t hdhomerun_control_get_device_id_requested(struct hdhomerun_control_sock_t *cs) -{ - return cs->desired_device_id; -} - -uint32_t hdhomerun_control_get_device_ip_requested(struct hdhomerun_control_sock_t *cs) -{ - return cs->desired_device_ip; -} - -uint32_t hdhomerun_control_get_local_addr(struct hdhomerun_control_sock_t *cs) -{ - if (!hdhomerun_control_connect_sock(cs)) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_local_addr: connect failed\n"); - return 0; - } - - struct sockaddr_in sock_addr; - socklen_t sockaddr_size = sizeof(sock_addr); - if (getsockname(cs->sock, (struct sockaddr*)&sock_addr, &sockaddr_size) != 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_local_addr: getsockname failed (%d)\n", sock_getlasterror); - return 0; - } - - return ntohl(sock_addr.sin_addr.s_addr); -} - -static int hdhomerun_control_send_sock(struct hdhomerun_control_sock_t *cs, struct hdhomerun_pkt_t *tx_pkt) -{ - int length = (int)(tx_pkt->end - tx_pkt->start); - if (send(cs->sock, (char *)tx_pkt->start, (int)length, 0) != length) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_send_sock: send failed (%d)\n", sock_getlasterror); - hdhomerun_control_close_sock(cs); - return -1; - } - - return 1; -} - -static int hdhomerun_control_recv_sock(struct hdhomerun_control_sock_t *cs, struct hdhomerun_pkt_t *rx_pkt, uint16_t *ptype, uint64_t recv_timeout) -{ - uint64_t stop_time = getcurrenttime() + recv_timeout; - hdhomerun_pkt_reset(rx_pkt); - - while (getcurrenttime() < stop_time) { - struct timeval t; - t.tv_sec = 0; - t.tv_usec = 250000; - - fd_set readfds; - FD_ZERO(&readfds); - FD_SET(cs->sock, &readfds); - - if (select(cs->sock+1, &readfds, NULL, NULL, &t) < 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_recv_sock: select failed (%d)\n", sock_getlasterror); - hdhomerun_control_close_sock(cs); - return -1; - } - - if (!FD_ISSET(cs->sock, &readfds)) { - continue; - } - - int rx_length = recv(cs->sock, (char *)rx_pkt->end, (int)(rx_pkt->limit - rx_pkt->end), 0); - if (rx_length <= 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_recv_sock: recv failed (%d)\n", sock_getlasterror); - hdhomerun_control_close_sock(cs); - return -1; - } - rx_pkt->end += rx_length; - - int ret = hdhomerun_pkt_open_frame(rx_pkt, ptype); - if (ret < 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_recv_sock: frame error\n"); - hdhomerun_control_close_sock(cs); - return -1; - } - if (ret == 0) { - continue; - } - - return 1; - } - - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_recv_sock: timeout\n"); - hdhomerun_control_close_sock(cs); - return -1; -} - -static int hdhomerun_control_send_recv_internal(struct hdhomerun_control_sock_t *cs, struct hdhomerun_pkt_t *tx_pkt, struct hdhomerun_pkt_t *rx_pkt, uint16_t type, uint64_t recv_timeout) -{ - hdhomerun_pkt_seal_frame(tx_pkt, type); - - int i; - for (i = 0; i < 2; i++) { - if (cs->sock == -1) { - if (!hdhomerun_control_connect_sock(cs)) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_send_recv: connect failed\n"); - return -1; - } - } - - if (hdhomerun_control_send_sock(cs, tx_pkt) < 0) { - continue; - } - if (!rx_pkt) { - return 1; - } - - uint16_t rsp_type; - if (hdhomerun_control_recv_sock(cs, rx_pkt, &rsp_type, recv_timeout) < 0) { - continue; - } - if (rsp_type != type + 1) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_send_recv: unexpected frame type\n"); - hdhomerun_control_close_sock(cs); - continue; - } - - return 1; - } - - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_send_recv: failed\n"); - return -1; -} - -int hdhomerun_control_send_recv(struct hdhomerun_control_sock_t *cs, struct hdhomerun_pkt_t *tx_pkt, struct hdhomerun_pkt_t *rx_pkt, uint16_t type) -{ - return hdhomerun_control_send_recv_internal(cs, tx_pkt, rx_pkt, type, HDHOMERUN_CONTROL_RECV_TIMEOUT); -} - -static int hdhomerun_control_get_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror) -{ - struct hdhomerun_pkt_t *tx_pkt = &cs->tx_pkt; - struct hdhomerun_pkt_t *rx_pkt = &cs->rx_pkt; - - /* Request. */ - hdhomerun_pkt_reset(tx_pkt); - - int name_len = (int)strlen(name) + 1; - if (tx_pkt->end + 3 + name_len > tx_pkt->limit) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: request too long\n"); - return -1; - } - hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_NAME); - hdhomerun_pkt_write_var_length(tx_pkt, name_len); - hdhomerun_pkt_write_mem(tx_pkt, (void *)name, name_len); - - if (value) { - int value_len = (int)strlen(value) + 1; - if (tx_pkt->end + 3 + value_len > tx_pkt->limit) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: request too long\n"); - return -1; - } - hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_VALUE); - hdhomerun_pkt_write_var_length(tx_pkt, value_len); - hdhomerun_pkt_write_mem(tx_pkt, (void *)value, value_len); - } - - if (lockkey != 0) { - if (tx_pkt->end + 6 > tx_pkt->limit) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: request too long\n"); - return -1; - } - hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_GETSET_LOCKKEY); - hdhomerun_pkt_write_var_length(tx_pkt, 4); - hdhomerun_pkt_write_u32(tx_pkt, lockkey); - } - - /* Send/Recv. */ - if (hdhomerun_control_send_recv_internal(cs, tx_pkt, rx_pkt, HDHOMERUN_TYPE_GETSET_REQ, HDHOMERUN_CONTROL_RECV_TIMEOUT) < 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: send/recv error\n"); - return -1; - } - - /* Response. */ - while (1) { - uint8_t tag; - size_t len; - uint8_t *next = hdhomerun_pkt_read_tlv(rx_pkt, &tag, &len); - if (!next) { - break; - } - - switch (tag) { - case HDHOMERUN_TAG_GETSET_VALUE: - if (pvalue) { - *pvalue = (char *)rx_pkt->pos; - rx_pkt->pos[len] = 0; - } - if (perror) { - *perror = NULL; - } - return 1; - - case HDHOMERUN_TAG_ERROR_MESSAGE: - rx_pkt->pos[len] = 0; - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: %s\n", rx_pkt->pos); - - if (pvalue) { - *pvalue = NULL; - } - if (perror) { - *perror = (char *)rx_pkt->pos; - } - - return 0; - } - - rx_pkt->pos = next; - } - - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_get_set: missing response tags\n"); - return -1; -} - -int hdhomerun_control_get(struct hdhomerun_control_sock_t *cs, const char *name, char **pvalue, char **perror) -{ - return hdhomerun_control_get_set(cs, name, NULL, 0, pvalue, perror); -} - -int hdhomerun_control_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, char **pvalue, char **perror) -{ - return hdhomerun_control_get_set(cs, name, value, 0, pvalue, perror); -} - -int hdhomerun_control_set_with_lockkey(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror) -{ - return hdhomerun_control_get_set(cs, name, value, lockkey, pvalue, perror); -} - -int hdhomerun_control_upgrade(struct hdhomerun_control_sock_t *cs, FILE *upgrade_file) -{ - struct hdhomerun_pkt_t *tx_pkt = &cs->tx_pkt; - struct hdhomerun_pkt_t *rx_pkt = &cs->rx_pkt; - uint32_t sequence = 0; - - /* Upload. */ - while (1) { - uint8_t data[256]; - size_t length = fread(data, 1, 256, upgrade_file); - if (length == 0) { - break; - } - - hdhomerun_pkt_reset(tx_pkt); - hdhomerun_pkt_write_u32(tx_pkt, sequence); - hdhomerun_pkt_write_mem(tx_pkt, data, length); - - if (hdhomerun_control_send_recv_internal(cs, tx_pkt, NULL, HDHOMERUN_TYPE_UPGRADE_REQ, 0) < 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_upgrade: send/recv failed\n"); - return -1; - } - - sequence += (uint32_t)length; - } - - if (sequence == 0) { - /* No data in file. Error, but no need to close connection. */ - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_upgrade: zero length file\n"); - return 0; - } - - /* Execute upgrade. */ - hdhomerun_pkt_reset(tx_pkt); - hdhomerun_pkt_write_u32(tx_pkt, 0xFFFFFFFF); - - if (hdhomerun_control_send_recv_internal(cs, tx_pkt, rx_pkt, HDHOMERUN_TYPE_UPGRADE_REQ, HDHOMERUN_CONTROL_UPGRADE_TIMEOUT) < 0) { - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_upgrade: send/recv failed\n"); - return -1; - } - - /* Check response. */ - while (1) { - uint8_t tag; - size_t len; - uint8_t *next = hdhomerun_pkt_read_tlv(rx_pkt, &tag, &len); - if (!next) { - break; - } - - switch (tag) { - case HDHOMERUN_TAG_ERROR_MESSAGE: - rx_pkt->pos[len] = 0; - hdhomerun_debug_printf(cs->dbg, "hdhomerun_control_upgrade: %s\n", (char *)rx_pkt->pos); - return 0; - - default: - break; - } - - rx_pkt->pos = next; - } - - return 1; -} diff --git a/lib/libhdhomerun/hdhomerun_control.h b/lib/libhdhomerun/hdhomerun_control.h deleted file mode 100644 index 170ed1d428e83..0000000000000 --- a/lib/libhdhomerun/hdhomerun_control.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * hdhomerun_control.h - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_control_sock_t; - -/* - * Create a control socket. - * - * This function will not attempt to connect to the device. - * The connection will be established when first used. - * - * uint32_t device_id = 32-bit device id of device. Set to HDHOMERUN_DEVICE_ID_WILDCARD to match any device ID. - * uint32_t device_ip = IP address of device. Set to 0 to auto-detect. - * struct hdhomerun_debug_t *dbg: Pointer to debug logging object. May be NULL. - * - * Returns a pointer to the newly created control socket. - * - * When no longer needed, the socket should be destroyed by calling hdhomerun_control_destroy. - */ -extern LIBTYPE struct hdhomerun_control_sock_t *hdhomerun_control_create(uint32_t device_id, uint32_t device_ip, struct hdhomerun_debug_t *dbg); -extern LIBTYPE void hdhomerun_control_destroy(struct hdhomerun_control_sock_t *cs); - -/* - * Get the actual device id or ip of the device. - * - * Returns 0 if the device id cannot be determined. - */ -extern LIBTYPE uint32_t hdhomerun_control_get_device_id(struct hdhomerun_control_sock_t *cs); -extern LIBTYPE uint32_t hdhomerun_control_get_device_ip(struct hdhomerun_control_sock_t *cs); -extern LIBTYPE uint32_t hdhomerun_control_get_device_id_requested(struct hdhomerun_control_sock_t *cs); -extern LIBTYPE uint32_t hdhomerun_control_get_device_ip_requested(struct hdhomerun_control_sock_t *cs); - -extern LIBTYPE void hdhomerun_control_set_device(struct hdhomerun_control_sock_t *cs, uint32_t device_id, uint32_t device_ip); - -/* - * Get the local machine IP address used when communicating with the device. - * - * This function is useful for determining the IP address to use with set target commands. - * - * Returns 32-bit IP address with native endianness, or 0 on error. - */ -extern LIBTYPE uint32_t hdhomerun_control_get_local_addr(struct hdhomerun_control_sock_t *cs); - -/* - * Low-level communication. - */ -extern LIBTYPE int hdhomerun_control_send_recv(struct hdhomerun_control_sock_t *cs, struct hdhomerun_pkt_t *tx_pkt, struct hdhomerun_pkt_t *rx_pkt, uint16_t type); - -/* - * Get/set a control variable on the device. - * - * const char *name: The name of var to get/set (c-string). The supported vars is device/firmware dependant. - * const char *value: The value to set (c-string). The format is device/firmware dependant. - - * char **pvalue: If provided, the caller-supplied char pointer will be populated with a pointer to the value - * string returned by the device, or NULL if the device returned an error string. The string will remain - * valid until the next call to a control sock function. - * char **perror: If provided, the caller-supplied char pointer will be populated with a pointer to the error - * string returned by the device, or NULL if the device returned an value string. The string will remain - * valid until the next call to a control sock function. - * - * Returns 1 if the operation was successful (pvalue set, perror NULL). - * Returns 0 if the operation was rejected (pvalue NULL, perror set). - * Returns -1 if a communication error occurs. - */ -extern LIBTYPE int hdhomerun_control_get(struct hdhomerun_control_sock_t *cs, const char *name, char **pvalue, char **perror); -extern LIBTYPE int hdhomerun_control_set(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, char **pvalue, char **perror); -extern LIBTYPE int hdhomerun_control_set_with_lockkey(struct hdhomerun_control_sock_t *cs, const char *name, const char *value, uint32_t lockkey, char **pvalue, char **perror); - -/* - * Upload new firmware to the device. - * - * FILE *upgrade_file: File pointer to read from. The file must have been opened in binary mode for reading. - * - * Returns 1 if the upload succeeded. - * Returns 0 if the upload was rejected. - * Returns -1 if an error occurs. - */ -extern LIBTYPE int hdhomerun_control_upgrade(struct hdhomerun_control_sock_t *cs, FILE *upgrade_file); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_debug.c b/lib/libhdhomerun/hdhomerun_debug.c deleted file mode 100644 index 7861e4e4ade25..0000000000000 --- a/lib/libhdhomerun/hdhomerun_debug.c +++ /dev/null @@ -1,464 +0,0 @@ -/* - * hdhomerun_debug.c - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -/* - * The debug logging includes optional support for connecting to the - * Silicondust support server. This option should not be used without - * being explicitly enabled by the user. Debug information should be - * limited to information useful to diagnosing a problem. - * - Silicondust. - */ - -#include "hdhomerun.h" - -#if !defined(HDHOMERUN_DEBUG_HOST) -#define HDHOMERUN_DEBUG_HOST "debug.silicondust.com" -#endif -#if !defined(HDHOMERUN_DEBUG_PORT) -#define HDHOMERUN_DEBUG_PORT "8002" -#endif - -struct hdhomerun_debug_message_t -{ - struct hdhomerun_debug_message_t *next; - struct hdhomerun_debug_message_t *prev; - char buffer[2048]; -}; - -struct hdhomerun_debug_t -{ - pthread_t thread; - volatile bool_t enabled; - volatile bool_t terminate; - char *prefix; - - pthread_mutex_t print_lock; - pthread_mutex_t queue_lock; - pthread_mutex_t send_lock; - - struct hdhomerun_debug_message_t *queue_head; - struct hdhomerun_debug_message_t *queue_tail; - uint32_t queue_depth; - - uint64_t connect_delay; - - char *file_name; - FILE *file_fp; - int sock; -}; - -static THREAD_FUNC_PREFIX hdhomerun_debug_thread_execute(void *arg); - -struct hdhomerun_debug_t *hdhomerun_debug_create(void) -{ - struct hdhomerun_debug_t *dbg = (struct hdhomerun_debug_t *)calloc(1, sizeof(struct hdhomerun_debug_t)); - if (!dbg) { - return NULL; - } - - dbg->sock = -1; - - pthread_mutex_init(&dbg->print_lock, NULL); - pthread_mutex_init(&dbg->queue_lock, NULL); - pthread_mutex_init(&dbg->send_lock, NULL); - - if (pthread_create(&dbg->thread, NULL, &hdhomerun_debug_thread_execute, dbg) != 0) { - free(dbg); - return NULL; - } - - return dbg; -} - -/* Send lock held by caller */ -static void hdhomerun_debug_close_file(struct hdhomerun_debug_t *dbg) -{ - if (!dbg->file_fp) { - return; - } - - fclose(dbg->file_fp); - dbg->file_fp = NULL; -} - -/* Send lock held by caller */ -static void hdhomerun_debug_close_sock(struct hdhomerun_debug_t *dbg) -{ - if (dbg->sock == -1) { - return; - } - - close(dbg->sock); - dbg->sock = -1; -} - -void hdhomerun_debug_destroy(struct hdhomerun_debug_t *dbg) -{ - dbg->terminate = TRUE; - pthread_join(dbg->thread, NULL); - - hdhomerun_debug_close_file(dbg); - hdhomerun_debug_close_sock(dbg); - - if (dbg->prefix) { - free(dbg->prefix); - } - - free(dbg); -} - -void hdhomerun_debug_set_prefix(struct hdhomerun_debug_t *dbg, const char *prefix) -{ - pthread_mutex_lock(&dbg->print_lock); - - if (dbg->prefix) { - free(dbg->prefix); - dbg->prefix = NULL; - } - - if (prefix) { - dbg->prefix = strdup(prefix); - } - - pthread_mutex_unlock(&dbg->print_lock); -} - -void hdhomerun_debug_set_filename(struct hdhomerun_debug_t *dbg, const char *filename) -{ - pthread_mutex_lock(&dbg->send_lock); - - if (!filename && !dbg->file_name) { - pthread_mutex_unlock(&dbg->send_lock); - return; - } - if (filename && dbg->file_name) { - if (strcmp(filename, dbg->file_name) == 0) { - pthread_mutex_unlock(&dbg->send_lock); - return; - } - } - - hdhomerun_debug_close_file(dbg); - hdhomerun_debug_close_sock(dbg); - - if (dbg->file_name) { - free(dbg->file_name); - dbg->file_name = NULL; - } - if (filename) { - dbg->file_name = strdup(filename); - } - - pthread_mutex_unlock(&dbg->send_lock); -} - -void hdhomerun_debug_enable(struct hdhomerun_debug_t *dbg) -{ - pthread_mutex_lock(&dbg->send_lock); - - dbg->enabled = TRUE; - - pthread_mutex_unlock(&dbg->send_lock); -} - -void hdhomerun_debug_disable(struct hdhomerun_debug_t *dbg) -{ - pthread_mutex_lock(&dbg->send_lock); - - dbg->enabled = FALSE; - hdhomerun_debug_close_file(dbg); - hdhomerun_debug_close_sock(dbg); - - pthread_mutex_unlock(&dbg->send_lock); -} - -bool_t hdhomerun_debug_enabled(struct hdhomerun_debug_t *dbg) -{ - if (!dbg) { - return FALSE; - } - - return dbg->enabled; -} - -void hdhomerun_debug_flush(struct hdhomerun_debug_t *dbg, uint64_t timeout) -{ - timeout = getcurrenttime() + timeout; - - while (getcurrenttime() < timeout) { - pthread_mutex_lock(&dbg->queue_lock); - struct hdhomerun_debug_message_t *message = dbg->queue_tail; - pthread_mutex_unlock(&dbg->queue_lock); - - if (!message) { - return; - } - - msleep(10); - } -} - -void hdhomerun_debug_printf(struct hdhomerun_debug_t *dbg, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - hdhomerun_debug_vprintf(dbg, fmt, args); - va_end(args); -} - -void hdhomerun_debug_vprintf(struct hdhomerun_debug_t *dbg, const char *fmt, va_list args) -{ - if (!dbg) { - return; - } - if (!dbg->enabled) { - return; - } - - struct hdhomerun_debug_message_t *message = (struct hdhomerun_debug_message_t *)malloc(sizeof(struct hdhomerun_debug_message_t)); - if (!message) { - return; - } - - char *ptr = message->buffer; - char *end = message->buffer + sizeof(message->buffer) - 2; - *end = 0; - - /* - * Timestamp. - */ - time_t current_time = time(NULL); - ptr += strftime(ptr, end - ptr, "%Y%m%d-%H:%M:%S ", localtime(¤t_time)); - if (ptr > end) { - ptr = end; - } - - /* - * Debug prefix. - */ - pthread_mutex_lock(&dbg->print_lock); - - if (dbg->prefix) { - int len = snprintf(ptr, end - ptr, "%s ", dbg->prefix); - len = (len <= 0) ? 0 : len; - ptr += len; - if (ptr > end) { - ptr = end; - } - } - - pthread_mutex_unlock(&dbg->print_lock); - - /* - * Message text. - */ - int len = vsnprintf(ptr, end - ptr, fmt, args); - len = (len < 0) ? 0 : len; /* len does not include null */ - ptr += len; - if (ptr > end) { - ptr = end; - } - - /* - * Force newline. - */ - if ((ptr[-1] != '\n') && (ptr + 1 <= end)) { - *ptr++ = '\n'; - } - - /* - * Force NULL. - */ - if (ptr + 1 > end) { - ptr = end - 1; - } - *ptr++ = 0; - - /* - * Enqueue. - */ - pthread_mutex_lock(&dbg->queue_lock); - - message->prev = NULL; - message->next = dbg->queue_head; - dbg->queue_head = message; - if (message->next) { - message->next->prev = message; - } else { - dbg->queue_tail = message; - } - dbg->queue_depth++; - - pthread_mutex_unlock(&dbg->queue_lock); -} - -/* Send lock held by caller */ -static bool_t hdhomerun_debug_output_message_file(struct hdhomerun_debug_t *dbg, struct hdhomerun_debug_message_t *message) -{ - if (!dbg->file_fp) { - uint64_t current_time = getcurrenttime(); - if (current_time < dbg->connect_delay) { - return FALSE; - } - dbg->connect_delay = current_time + 30*1000; - - dbg->file_fp = fopen(dbg->file_name, "a"); - if (!dbg->file_fp) { - return FALSE; - } - } - - fprintf(dbg->file_fp, "%s", message->buffer); - fflush(dbg->file_fp); - - return TRUE; -} - -/* Send lock held by caller */ -#if defined(__CYGWIN__) -static bool_t hdhomerun_debug_output_message_sock(struct hdhomerun_debug_t *dbg, struct hdhomerun_debug_message_t *message) -{ - return TRUE; -} -#else -static bool_t hdhomerun_debug_output_message_sock(struct hdhomerun_debug_t *dbg, struct hdhomerun_debug_message_t *message) -{ - if (dbg->sock == -1) { - uint64_t current_time = getcurrenttime(); - if (current_time < dbg->connect_delay) { - return FALSE; - } - dbg->connect_delay = current_time + 30*1000; - - dbg->sock = (int)socket(AF_INET, SOCK_STREAM, 0); - if (dbg->sock == -1) { - return FALSE; - } - - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - struct addrinfo *sock_info; - if (getaddrinfo(HDHOMERUN_DEBUG_HOST, HDHOMERUN_DEBUG_PORT, &hints, &sock_info) != 0) { - hdhomerun_debug_close_sock(dbg); - return FALSE; - } - if (connect(dbg->sock, sock_info->ai_addr, (int)sock_info->ai_addrlen) != 0) { - freeaddrinfo(sock_info); - hdhomerun_debug_close_sock(dbg); - return FALSE; - } - freeaddrinfo(sock_info); - } - - size_t length = strlen(message->buffer); - if (send(dbg->sock, (char *)message->buffer, (int)length, 0) != length) { - hdhomerun_debug_close_sock(dbg); - return FALSE; - } - - return TRUE; -} -#endif - -static bool_t hdhomerun_debug_output_message(struct hdhomerun_debug_t *dbg, struct hdhomerun_debug_message_t *message) -{ - pthread_mutex_lock(&dbg->send_lock); - - if (!dbg->enabled) { - pthread_mutex_unlock(&dbg->send_lock); - return TRUE; - } - - bool_t ret; - if (dbg->file_name) { - ret = hdhomerun_debug_output_message_file(dbg, message); - } else { - ret = hdhomerun_debug_output_message_sock(dbg, message); - } - - pthread_mutex_unlock(&dbg->send_lock); - return ret; -} - -static void hdhomerun_debug_pop_and_free_message(struct hdhomerun_debug_t *dbg) -{ - pthread_mutex_lock(&dbg->queue_lock); - - struct hdhomerun_debug_message_t *message = dbg->queue_tail; - dbg->queue_tail = message->prev; - if (message->prev) { - message->prev->next = NULL; - } else { - dbg->queue_head = NULL; - } - dbg->queue_depth--; - - pthread_mutex_unlock(&dbg->queue_lock); - - free(message); -} - -static THREAD_FUNC_PREFIX hdhomerun_debug_thread_execute(void *arg) -{ - struct hdhomerun_debug_t *dbg = (struct hdhomerun_debug_t *)arg; - - while (!dbg->terminate) { - - pthread_mutex_lock(&dbg->queue_lock); - struct hdhomerun_debug_message_t *message = dbg->queue_tail; - uint32_t queue_depth = dbg->queue_depth; - pthread_mutex_unlock(&dbg->queue_lock); - - if (!message) { - msleep(250); - continue; - } - - if (queue_depth > 256) { - hdhomerun_debug_pop_and_free_message(dbg); - continue; - } - - if (!hdhomerun_debug_output_message(dbg, message)) { - msleep(250); - continue; - } - - hdhomerun_debug_pop_and_free_message(dbg); - } - - return 0; -} diff --git a/lib/libhdhomerun/hdhomerun_debug.h b/lib/libhdhomerun/hdhomerun_debug.h deleted file mode 100644 index a8f996b63c489..0000000000000 --- a/lib/libhdhomerun/hdhomerun_debug.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * hdhomerun_debug.h - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -/* - * The debug logging includes optional support for connecting to the - * Silicondust support server. This option should not be used without - * being explicitly enabled by the user. Debug information should be - * limited to information useful to diagnosing a problem. - * - Silicondust. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_debug_t; - -extern LIBTYPE struct hdhomerun_debug_t *hdhomerun_debug_create(void); -extern LIBTYPE void hdhomerun_debug_destroy(struct hdhomerun_debug_t *dbg); - -extern LIBTYPE void hdhomerun_debug_set_prefix(struct hdhomerun_debug_t *dbg, const char *prefix); -extern LIBTYPE void hdhomerun_debug_set_filename(struct hdhomerun_debug_t *dbg, const char *filename); -extern LIBTYPE void hdhomerun_debug_enable(struct hdhomerun_debug_t *dbg); -extern LIBTYPE void hdhomerun_debug_disable(struct hdhomerun_debug_t *dbg); -extern LIBTYPE bool_t hdhomerun_debug_enabled(struct hdhomerun_debug_t *dbg); - -extern LIBTYPE void hdhomerun_debug_flush(struct hdhomerun_debug_t *dbg, uint64_t timeout); - -extern LIBTYPE void hdhomerun_debug_printf(struct hdhomerun_debug_t *dbg, const char *fmt, ...); -extern LIBTYPE void hdhomerun_debug_vprintf(struct hdhomerun_debug_t *dbg, const char *fmt, va_list args); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_device.c b/lib/libhdhomerun/hdhomerun_device.c deleted file mode 100644 index 2f253b40ed28b..0000000000000 --- a/lib/libhdhomerun/hdhomerun_device.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - * hdhomerun_device.c - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -struct hdhomerun_device_t { - struct hdhomerun_control_sock_t *cs; - struct hdhomerun_video_sock_t *vs; - struct hdhomerun_debug_t *dbg; - struct hdhomerun_channelscan_t *scan; - unsigned int tuner; - uint32_t lockkey; - char name[32]; - char model[32]; -}; - -static void hdhomerun_device_set_update(struct hdhomerun_device_t *hd) -{ - /* Clear cached information. */ - *hd->model = 0; - - /* New name. */ - sprintf(hd->name, "%08lX-%u", (unsigned long)hdhomerun_control_get_device_id(hd->cs), hd->tuner); -} - -void hdhomerun_device_set_device(struct hdhomerun_device_t *hd, uint32_t device_id, uint32_t device_ip) -{ - hdhomerun_control_set_device(hd->cs, device_id, device_ip); - hdhomerun_device_set_update(hd); -} - -void hdhomerun_device_set_tuner(struct hdhomerun_device_t *hd, unsigned int tuner) -{ - hd->tuner = tuner; - hdhomerun_device_set_update(hd); -} - -struct hdhomerun_device_t *hdhomerun_device_create(uint32_t device_id, uint32_t device_ip, unsigned int tuner, struct hdhomerun_debug_t *dbg) -{ - struct hdhomerun_device_t *hd = (struct hdhomerun_device_t *)calloc(1, sizeof(struct hdhomerun_device_t)); - if (!hd) { - hdhomerun_debug_printf(dbg, "hdhomerun_device_create: failed to allocate device object\n"); - return NULL; - } - - hd->dbg = dbg; - - hd->cs = hdhomerun_control_create(0, 0, hd->dbg); - if (!hd->cs) { - hdhomerun_debug_printf(hd->dbg, "hdhomerun_device_create: failed to create control object\n"); - free(hd); - return NULL; - } - - hdhomerun_device_set_device(hd, device_id, device_ip); - hdhomerun_device_set_tuner(hd, tuner); - - return hd; -} - -void hdhomerun_device_destroy(struct hdhomerun_device_t *hd) -{ - if (hd->scan) { - channelscan_destroy(hd->scan); - } - - if (hd->vs) { - hdhomerun_video_destroy(hd->vs); - } - - hdhomerun_control_destroy(hd->cs); - - free(hd); -} - -static bool_t is_hex_char(char c) -{ - if ((c >= '0') && (c <= '9')) { - return TRUE; - } - if ((c >= 'A') && (c <= 'F')) { - return TRUE; - } - if ((c >= 'a') && (c <= 'f')) { - return TRUE; - } - return FALSE; -} - -static struct hdhomerun_device_t *hdhomerun_device_create_from_str_device_id(const char *device_str, struct hdhomerun_debug_t *dbg) -{ - int i; - const char *ptr = device_str; - for (i = 0; i < 8; i++) { - if (!is_hex_char(*ptr++)) { - return NULL; - } - } - - if (*ptr == 0) { - unsigned long device_id; - if (sscanf(device_str, "%lx", &device_id) != 1) { - return NULL; - } - return hdhomerun_device_create((uint32_t)device_id, 0, 0, dbg); - } - - if (*ptr == '-') { - unsigned long device_id; - unsigned int tuner; - if (sscanf(device_str, "%lx-%u", &device_id, &tuner) != 2) { - return NULL; - } - return hdhomerun_device_create((uint32_t)device_id, 0, tuner, dbg); - } - - return NULL; -} - -static struct hdhomerun_device_t *hdhomerun_device_create_from_str_ip(const char *device_str, struct hdhomerun_debug_t *dbg) -{ - unsigned long a[4]; - if (sscanf(device_str, "%lu.%lu.%lu.%lu", &a[0], &a[1], &a[2], &a[3]) != 4) { - return NULL; - } - - unsigned long device_ip = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0); - return hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, (uint32_t)device_ip, 0, dbg); -} - -static struct hdhomerun_device_t *hdhomerun_device_create_from_str_dns(const char *device_str, struct hdhomerun_debug_t *dbg) -{ -#if defined(__CYGWIN__) - return NULL; -#else - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - - struct addrinfo *sock_info; - if (getaddrinfo(device_str, "65001", &hints, &sock_info) != 0) { - return NULL; - } - - struct sockaddr_in *sock_addr = (struct sockaddr_in *)sock_info->ai_addr; - uint32_t device_ip = ntohl(sock_addr->sin_addr.s_addr); - freeaddrinfo(sock_info); - - if (device_ip == 0) { - return NULL; - } - - return hdhomerun_device_create(HDHOMERUN_DEVICE_ID_WILDCARD, (uint32_t)device_ip, 0, dbg); -#endif -} - -struct hdhomerun_device_t *hdhomerun_device_create_from_str(const char *device_str, struct hdhomerun_debug_t *dbg) -{ - struct hdhomerun_device_t *device = hdhomerun_device_create_from_str_device_id(device_str, dbg); - if (device) { - return device; - } - - device = hdhomerun_device_create_from_str_ip(device_str, dbg); - if (device) { - return device; - } - - device = hdhomerun_device_create_from_str_dns(device_str, dbg); - if (device) { - return device; - } - - return NULL; -} - -int hdhomerun_device_set_tuner_from_str(struct hdhomerun_device_t *hd, const char *tuner_str) -{ - unsigned int tuner; - if (sscanf(tuner_str, "%u", &tuner) == 1) { - hdhomerun_device_set_tuner(hd, tuner); - return 1; - } - if (sscanf(tuner_str, "/tuner%u", &tuner) == 1) { - hdhomerun_device_set_tuner(hd, tuner); - return 1; - } - - return -1; -} - -uint32_t hdhomerun_device_get_device_id(struct hdhomerun_device_t *hd) -{ - return hdhomerun_control_get_device_id(hd->cs); -} - -uint32_t hdhomerun_device_get_device_ip(struct hdhomerun_device_t *hd) -{ - return hdhomerun_control_get_device_ip(hd->cs); -} - -uint32_t hdhomerun_device_get_device_id_requested(struct hdhomerun_device_t *hd) -{ - return hdhomerun_control_get_device_id_requested(hd->cs); -} - -uint32_t hdhomerun_device_get_device_ip_requested(struct hdhomerun_device_t *hd) -{ - return hdhomerun_control_get_device_ip_requested(hd->cs); -} - -unsigned int hdhomerun_device_get_tuner(struct hdhomerun_device_t *hd) -{ - return hd->tuner; -} - -struct hdhomerun_control_sock_t *hdhomerun_device_get_control_sock(struct hdhomerun_device_t *hd) -{ - return hd->cs; -} - -struct hdhomerun_video_sock_t *hdhomerun_device_get_video_sock(struct hdhomerun_device_t *hd) -{ - if (hd->vs) { - return hd->vs; - } - - hd->vs = hdhomerun_video_create(0, VIDEO_DATA_BUFFER_SIZE_1S * 2, hd->dbg); - if (!hd->vs) { - hdhomerun_debug_printf(hd->dbg, "hdhomerun_device_get_video_sock: failed to create video object\n"); - return NULL; - } - - return hd->vs; -} - -uint32_t hdhomerun_device_get_local_machine_addr(struct hdhomerun_device_t *hd) -{ - return hdhomerun_control_get_local_addr(hd->cs); -} - -static uint32_t hdhomerun_device_get_status_parse(const char *status_str, const char *tag) -{ - const char *ptr = strstr(status_str, tag); - if (!ptr) { - return 0; - } - - unsigned long value = 0; - sscanf(ptr + strlen(tag), "%lu", &value); - - return (uint32_t)value; -} - -static bool_t hdhomerun_device_get_tuner_status_lock_is_bcast(struct hdhomerun_tuner_status_t *status) -{ - if (strcmp(status->lock_str, "8vsb") == 0) { - return TRUE; - } - if (strncmp(status->lock_str, "t8", 2) == 0) { - return TRUE; - } - if (strncmp(status->lock_str, "t7", 2) == 0) { - return TRUE; - } - if (strncmp(status->lock_str, "t6", 2) == 0) { - return TRUE; - } - - return FALSE; -} - -uint32_t hdhomerun_device_get_tuner_status_ss_color(struct hdhomerun_tuner_status_t *status) -{ - unsigned int ss_yellow_min; - unsigned int ss_green_min; - - if (!status->lock_supported) { - return HDHOMERUN_STATUS_COLOR_NEUTRAL; - } - - if (hdhomerun_device_get_tuner_status_lock_is_bcast(status)) { - ss_yellow_min = 50; /* -30dBmV */ - ss_green_min = 75; /* -15dBmV */ - } else { - ss_yellow_min = 80; /* -12dBmV */ - ss_green_min = 90; /* -6dBmV */ - } - - if (status->signal_strength >= ss_green_min) { - return HDHOMERUN_STATUS_COLOR_GREEN; - } - if (status->signal_strength >= ss_yellow_min) { - return HDHOMERUN_STATUS_COLOR_YELLOW; - } - - return HDHOMERUN_STATUS_COLOR_RED; -} - -uint32_t hdhomerun_device_get_tuner_status_snq_color(struct hdhomerun_tuner_status_t *status) -{ - if (status->signal_to_noise_quality >= 70) { - return HDHOMERUN_STATUS_COLOR_GREEN; - } - if (status->signal_to_noise_quality >= 50) { - return HDHOMERUN_STATUS_COLOR_YELLOW; - } - - return HDHOMERUN_STATUS_COLOR_RED; -} - -uint32_t hdhomerun_device_get_tuner_status_seq_color(struct hdhomerun_tuner_status_t *status) -{ - if (status->symbol_error_quality >= 100) { - return HDHOMERUN_STATUS_COLOR_GREEN; - } - - return HDHOMERUN_STATUS_COLOR_RED; -} - -int hdhomerun_device_get_tuner_status(struct hdhomerun_device_t *hd, char **pstatus_str, struct hdhomerun_tuner_status_t *status) -{ - memset(status, 0, sizeof(struct hdhomerun_tuner_status_t)); - - char name[32]; - sprintf(name, "/tuner%u/status", hd->tuner); - - char *status_str; - int ret = hdhomerun_control_get(hd->cs, name, &status_str, NULL); - if (ret <= 0) { - return ret; - } - - if (pstatus_str) { - *pstatus_str = status_str; - } - - char *channel = strstr(status_str, "ch="); - if (channel) { - sscanf(channel + 3, "%31s", status->channel); - } - - char *lock = strstr(status_str, "lock="); - if (lock) { - sscanf(lock + 5, "%31s", status->lock_str); - } - - status->signal_strength = (unsigned int)hdhomerun_device_get_status_parse(status_str, "ss="); - status->signal_to_noise_quality = (unsigned int)hdhomerun_device_get_status_parse(status_str, "snq="); - status->symbol_error_quality = (unsigned int)hdhomerun_device_get_status_parse(status_str, "seq="); - status->raw_bits_per_second = hdhomerun_device_get_status_parse(status_str, "bps="); - status->packets_per_second = hdhomerun_device_get_status_parse(status_str, "pps="); - - status->signal_present = status->signal_strength >= 45; - - if (strcmp(status->lock_str, "none") != 0) { - if (status->lock_str[0] == '(') { - status->lock_unsupported = TRUE; - } else { - status->lock_supported = TRUE; - } - } - - return 1; -} - -int hdhomerun_device_get_tuner_streaminfo(struct hdhomerun_device_t *hd, char **pstreaminfo) -{ - char name[32]; - sprintf(name, "/tuner%u/streaminfo", hd->tuner); - return hdhomerun_control_get(hd->cs, name, pstreaminfo, NULL); -} - -int hdhomerun_device_get_tuner_channel(struct hdhomerun_device_t *hd, char **pchannel) -{ - char name[32]; - sprintf(name, "/tuner%u/channel", hd->tuner); - return hdhomerun_control_get(hd->cs, name, pchannel, NULL); -} - -int hdhomerun_device_get_tuner_channelmap(struct hdhomerun_device_t *hd, char **pchannelmap) -{ - char name[32]; - sprintf(name, "/tuner%u/channelmap", hd->tuner); - return hdhomerun_control_get(hd->cs, name, pchannelmap, NULL); -} - -int hdhomerun_device_get_tuner_filter(struct hdhomerun_device_t *hd, char **pfilter) -{ - char name[32]; - sprintf(name, "/tuner%u/filter", hd->tuner); - return hdhomerun_control_get(hd->cs, name, pfilter, NULL); -} - -int hdhomerun_device_get_tuner_program(struct hdhomerun_device_t *hd, char **pprogram) -{ - char name[32]; - sprintf(name, "/tuner%u/program", hd->tuner); - return hdhomerun_control_get(hd->cs, name, pprogram, NULL); -} - -int hdhomerun_device_get_tuner_target(struct hdhomerun_device_t *hd, char **ptarget) -{ - char name[32]; - sprintf(name, "/tuner%u/target", hd->tuner); - return hdhomerun_control_get(hd->cs, name, ptarget, NULL); -} - -int hdhomerun_device_get_tuner_plotsample(struct hdhomerun_device_t *hd, struct hdhomerun_plotsample_t **psamples, size_t *pcount) -{ - char name[32]; - sprintf(name, "/tuner%u/plotsample", hd->tuner); - - char *result; - int ret = hdhomerun_control_get(hd->cs, name, &result, NULL); - if (ret <= 0) { - return ret; - } - - struct hdhomerun_plotsample_t *samples = (struct hdhomerun_plotsample_t *)result; - *psamples = samples; - size_t count = 0; - - while (1) { - char *ptr = strchr(result, ' '); - if (!ptr) { - break; - } - *ptr++ = 0; - - unsigned long raw; - if (sscanf(result, "%lx", &raw) != 1) { - break; - } - - uint16_t real = (raw >> 12) & 0x0FFF; - if (real & 0x0800) { - real |= 0xF000; - } - - uint16_t imag = (raw >> 0) & 0x0FFF; - if (imag & 0x0800) { - imag |= 0xF000; - } - - samples->real = (int16_t)real; - samples->imag = (int16_t)imag; - samples++; - count++; - - result = ptr; - } - - *pcount = count; - return 1; -} - -int hdhomerun_device_get_tuner_lockkey_owner(struct hdhomerun_device_t *hd, char **powner) -{ - char name[32]; - sprintf(name, "/tuner%u/lockkey", hd->tuner); - return hdhomerun_control_get(hd->cs, name, powner, NULL); -} - -int hdhomerun_device_get_ir_target(struct hdhomerun_device_t *hd, char **ptarget) -{ - return hdhomerun_control_get(hd->cs, "/ir/target", ptarget, NULL); -} - -int hdhomerun_device_get_lineup_location(struct hdhomerun_device_t *hd, char **plocation) -{ - return hdhomerun_control_get(hd->cs, "/lineup/location", plocation, NULL); -} - -int hdhomerun_device_get_version(struct hdhomerun_device_t *hd, char **pversion_str, uint32_t *pversion_num) -{ - char *version_str; - int ret = hdhomerun_control_get(hd->cs, "/sys/version", &version_str, NULL); - if (ret <= 0) { - return ret; - } - - if (pversion_str) { - *pversion_str = version_str; - } - - if (pversion_num) { - unsigned long version_num; - if (sscanf(version_str, "%lu", &version_num) != 1) { - *pversion_num = 0; - } else { - *pversion_num = (uint32_t)version_num; - } - } - - return 1; -} - -int hdhomerun_device_set_tuner_channel(struct hdhomerun_device_t *hd, const char *channel) -{ - char name[32]; - sprintf(name, "/tuner%u/channel", hd->tuner); - return hdhomerun_control_set_with_lockkey(hd->cs, name, channel, hd->lockkey, NULL, NULL); -} - -int hdhomerun_device_set_tuner_channelmap(struct hdhomerun_device_t *hd, const char *channelmap) -{ - char name[32]; - sprintf(name, "/tuner%u/channelmap", hd->tuner); - return hdhomerun_control_set_with_lockkey(hd->cs, name, channelmap, hd->lockkey, NULL, NULL); -} - -int hdhomerun_device_set_tuner_filter(struct hdhomerun_device_t *hd, const char *filter) -{ - char name[32]; - sprintf(name, "/tuner%u/filter", hd->tuner); - return hdhomerun_control_set_with_lockkey(hd->cs, name, filter, hd->lockkey, NULL, NULL); -} - -static int hdhomerun_device_set_tuner_filter_by_array_append(char **pptr, char *end, uint16_t range_begin, uint16_t range_end) -{ - char *ptr = *pptr; - - size_t available = end - ptr; - size_t required; - - if (range_begin == range_end) { - required = snprintf(ptr, available, "0x%04x ", range_begin) + 1; - } else { - required = snprintf(ptr, available, "0x%04x-0x%04x ", range_begin, range_end) + 1; - } - - if (required > available) { - return FALSE; - } - - *pptr = strchr(ptr, 0); - return TRUE; -} - -int hdhomerun_device_set_tuner_filter_by_array(struct hdhomerun_device_t *hd, unsigned char filter_array[0x2000]) -{ - char filter[1024]; - char *ptr = filter; - char *end = filter + sizeof(filter); - - uint16_t range_begin = 0xFFFF; - uint16_t range_end = 0xFFFF; - - uint16_t i; - for (i = 0; i <= 0x1FFF; i++) { - if (!filter_array[i]) { - if (range_begin == 0xFFFF) { - continue; - } - if (!hdhomerun_device_set_tuner_filter_by_array_append(&ptr, end, range_begin, range_end)) { - return 0; - } - range_begin = 0xFFFF; - range_end = 0xFFFF; - continue; - } - - if (range_begin == 0xFFFF) { - range_begin = i; - range_end = i; - continue; - } - - range_end = i; - } - - if (range_begin != 0xFFFF) { - if (!hdhomerun_device_set_tuner_filter_by_array_append(&ptr, end, range_begin, range_end)) { - return 0; - } - } - - /* Remove trailing space. */ - if (ptr > filter) { - ptr--; - } - *ptr = 0; - - return hdhomerun_device_set_tuner_filter(hd, filter); -} - -int hdhomerun_device_set_tuner_program(struct hdhomerun_device_t *hd, const char *program) -{ - char name[32]; - sprintf(name, "/tuner%u/program", hd->tuner); - return hdhomerun_control_set_with_lockkey(hd->cs, name, program, hd->lockkey, NULL, NULL); -} - -int hdhomerun_device_set_tuner_target(struct hdhomerun_device_t *hd, char *target) -{ - char name[32]; - sprintf(name, "/tuner%u/target", hd->tuner); - return hdhomerun_control_set_with_lockkey(hd->cs, name, target, hd->lockkey, NULL, NULL); -} - -int hdhomerun_device_set_tuner_target_to_local_protocol(struct hdhomerun_device_t *hd, const char *protocol) -{ - /* Create video socket. */ - hdhomerun_device_get_video_sock(hd); - if (!hd->vs) { - return -1; - } - - /* Set target. */ - char target[64]; - uint32_t local_ip = hdhomerun_control_get_local_addr(hd->cs); - uint16_t local_port = hdhomerun_video_get_local_port(hd->vs); - sprintf(target, "%s://%u.%u.%u.%u:%u", - protocol, - (unsigned int)(local_ip >> 24) & 0xFF, (unsigned int)(local_ip >> 16) & 0xFF, - (unsigned int)(local_ip >> 8) & 0xFF, (unsigned int)(local_ip >> 0) & 0xFF, - (unsigned int)local_port - ); - - return hdhomerun_device_set_tuner_target(hd, target); -} - -int hdhomerun_device_set_tuner_target_to_local(struct hdhomerun_device_t *hd) -{ - return hdhomerun_device_set_tuner_target_to_local_protocol(hd, HDHOMERUN_TARGET_PROTOCOL_UDP); -} - -int hdhomerun_device_set_ir_target(struct hdhomerun_device_t *hd, const char *target) -{ - return hdhomerun_control_set(hd->cs, "/ir/target", target, NULL, NULL); -} - -int hdhomerun_device_set_lineup_location(struct hdhomerun_device_t *hd, const char *location) -{ - return hdhomerun_control_set(hd->cs, "/lineup/location", location, NULL, NULL); -} - -int hdhomerun_device_get_var(struct hdhomerun_device_t *hd, const char *name, char **pvalue, char **perror) -{ - return hdhomerun_control_get(hd->cs, name, pvalue, perror); -} - -int hdhomerun_device_set_var(struct hdhomerun_device_t *hd, const char *name, const char *value, char **pvalue, char **perror) -{ - return hdhomerun_control_set_with_lockkey(hd->cs, name, value, hd->lockkey, pvalue, perror); -} - -int hdhomerun_device_tuner_lockkey_request(struct hdhomerun_device_t *hd, char **perror) -{ - uint32_t new_lockkey = (uint32_t)getcurrenttime(); - - char name[32]; - sprintf(name, "/tuner%u/lockkey", hd->tuner); - - char new_lockkey_str[64]; - sprintf(new_lockkey_str, "%u", (unsigned int)new_lockkey); - - int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, new_lockkey_str, hd->lockkey, NULL, perror); - if (ret <= 0) { - hd->lockkey = 0; - return ret; - } - - hd->lockkey = new_lockkey; - return ret; -} - -int hdhomerun_device_tuner_lockkey_release(struct hdhomerun_device_t *hd) -{ - if (hd->lockkey == 0) { - return 1; - } - - char name[32]; - sprintf(name, "/tuner%u/lockkey", hd->tuner); - int ret = hdhomerun_control_set_with_lockkey(hd->cs, name, "none", hd->lockkey, NULL, NULL); - - hd->lockkey = 0; - return ret; -} - -int hdhomerun_device_tuner_lockkey_force(struct hdhomerun_device_t *hd) -{ - char name[32]; - sprintf(name, "/tuner%u/lockkey", hd->tuner); - int ret = hdhomerun_control_set(hd->cs, name, "force", NULL, NULL); - - hd->lockkey = 0; - return ret; -} - -void hdhomerun_device_tuner_lockkey_use_value(struct hdhomerun_device_t *hd, uint32_t lockkey) -{ - hd->lockkey = lockkey; -} - -int hdhomerun_device_wait_for_lock(struct hdhomerun_device_t *hd, struct hdhomerun_tuner_status_t *status) -{ - /* Delay for SS reading to be valid (signal present). */ - msleep(250); - - /* Wait for up to 2.5 seconds for lock. */ - uint64_t timeout = getcurrenttime() + 2500; - while (1) { - /* Get status to check for lock. Quality numbers will not be valid yet. */ - int ret = hdhomerun_device_get_tuner_status(hd, NULL, status); - if (ret <= 0) { - return ret; - } - - if (!status->signal_present) { - return 1; - } - if (status->lock_supported || status->lock_unsupported) { - return 1; - } - - if (getcurrenttime() >= timeout) { - return 1; - } - - msleep(250); - } -} - -int hdhomerun_device_stream_start(struct hdhomerun_device_t *hd) -{ - /* Set target. */ - int ret = hdhomerun_device_stream_refresh_target(hd); - if (ret <= 0) { - return ret; - } - - /* Flush video buffer. */ - msleep(64); - hdhomerun_video_flush(hd->vs); - - /* Success. */ - return 1; -} - -int hdhomerun_device_stream_refresh_target(struct hdhomerun_device_t *hd) -{ - return hdhomerun_device_set_tuner_target_to_local_protocol(hd, HDHOMERUN_TARGET_PROTOCOL_RTP); -} - -uint8_t *hdhomerun_device_stream_recv(struct hdhomerun_device_t *hd, size_t max_size, size_t *pactual_size) -{ - if (!hd->vs) { - return NULL; - } - return hdhomerun_video_recv(hd->vs, max_size, pactual_size); -} - -void hdhomerun_device_stream_flush(struct hdhomerun_device_t *hd) -{ - hdhomerun_video_flush(hd->vs); -} - -void hdhomerun_device_stream_stop(struct hdhomerun_device_t *hd) -{ - hdhomerun_device_set_tuner_target(hd, "none"); -} - -int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, const char *channelmap) -{ - if (hd->scan) { - channelscan_destroy(hd->scan); - } - - hd->scan = channelscan_create(hd, channelmap); - if (!hd->scan) { - return -1; - } - - return 1; -} - -int hdhomerun_device_channelscan_advance(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result) -{ - if (!hd->scan) { - return 0; - } - - int ret = channelscan_advance(hd->scan, result); - if (ret <= 0) { - channelscan_destroy(hd->scan); - hd->scan = NULL; - } - - return ret; -} - -int hdhomerun_device_channelscan_detect(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result) -{ - if (!hd->scan) { - return 0; - } - - int ret = channelscan_detect(hd->scan, result); - if (ret <= 0) { - channelscan_destroy(hd->scan); - hd->scan = NULL; - } - - return ret; -} - -uint8_t hdhomerun_device_channelscan_get_progress(struct hdhomerun_device_t *hd) -{ - if (!hd->scan) { - return 0; - } - - return channelscan_get_progress(hd->scan); -} - -int hdhomerun_device_firmware_version_check(struct hdhomerun_device_t *hd, uint32_t features) -{ - uint32_t version; - if (hdhomerun_device_get_version(hd, NULL, &version) <= 0) { - return -1; - } - - if (version < 20070219) { - return 0; - } - - return 1; -} - -const char *hdhomerun_device_get_model_str(struct hdhomerun_device_t *hd) -{ - if (*hd->model) { - return hd->model; - } - - char *model_str; - int ret = hdhomerun_control_get(hd->cs, "/sys/model", &model_str, NULL); - if (ret < 0) { - return NULL; - } - if (ret == 0) { - model_str = "hdhomerun_atsc"; - } - - strncpy(hd->model, model_str, sizeof(hd->model) - 1); - hd->model[sizeof(hd->model) - 1] = 0; - - return hd->model; -} - -int hdhomerun_device_upgrade(struct hdhomerun_device_t *hd, FILE *upgrade_file) -{ - hdhomerun_control_set(hd->cs, "/tuner0/lockkey", "force", NULL, NULL); - hdhomerun_control_set(hd->cs, "/tuner0/channel", "none", NULL, NULL); - - hdhomerun_control_set(hd->cs, "/tuner1/lockkey", "force", NULL, NULL); - hdhomerun_control_set(hd->cs, "/tuner1/channel", "none", NULL, NULL); - - return hdhomerun_control_upgrade(hd->cs, upgrade_file); -} - -void hdhomerun_device_debug_print_video_stats(struct hdhomerun_device_t *hd) -{ - if (!hdhomerun_debug_enabled(hd->dbg)) { - return; - } - - char name[32]; - sprintf(name, "/tuner%u/debug", hd->tuner); - - char *debug_str; - char *error_str; - int ret = hdhomerun_control_get(hd->cs, name, &debug_str, &error_str); - if (ret < 0) { - hdhomerun_debug_printf(hd->dbg, "video dev: communication error getting debug stats\n"); - return; - } - - if (error_str) { - hdhomerun_debug_printf(hd->dbg, "video dev: %s\n", error_str); - } else { - hdhomerun_debug_printf(hd->dbg, "video dev: %s\n", debug_str); - } - - if (hd->vs) { - hdhomerun_video_debug_print_stats(hd->vs); - } -} - -void hdhomerun_device_get_video_stats(struct hdhomerun_device_t *hd, struct hdhomerun_video_stats_t *stats) -{ - hdhomerun_video_get_stats(hd->vs, stats); -} diff --git a/lib/libhdhomerun/hdhomerun_device.h b/lib/libhdhomerun/hdhomerun_device.h deleted file mode 100644 index be424fe57d104..0000000000000 --- a/lib/libhdhomerun/hdhomerun_device.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * hdhomerun_device.h - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define HDHOMERUN_DEVICE_MAX_TUNE_TO_LOCK_TIME 1500 -#define HDHOMERUN_DEVICE_MAX_LOCK_TO_DATA_TIME 2000 -#define HDHOMERUN_DEVICE_MAX_TUNE_TO_DATA_TIME (HDHOMERUN_DEVICE_MAX_TUNE_TO_LOCK_TIME + HDHOMERUN_DEVICE_MAX_LOCK_TO_DATA_TIME) - -#define HDHOMERUN_STATUS_COLOR_NEUTRAL 0xFFFFFFFF -#define HDHOMERUN_STATUS_COLOR_RED 0xFFFF0000 -#define HDHOMERUN_STATUS_COLOR_YELLOW 0xFFFFFF00 -#define HDHOMERUN_STATUS_COLOR_GREEN 0xFF00C000 - -#define HDHOMERUN_TARGET_PROTOCOL_UDP "udp" -#define HDHOMERUN_TARGET_PROTOCOL_RTP "rtp" - -/* - * Create a device object. - * - * Typically a device object will be created for each tuner. - * It is valid to have multiple device objects communicating with a single HDHomeRun. - * - * For example, a threaded application that streams video from 4 tuners (2 HDHomeRun devices) and has - * GUI feedback to the user of the selected tuner might use 5 device objects: 4 for streaming video - * (one per thread) and one for the GUI display that can just between tuners. - * - * This function will not attempt to connect to the device. - * The connection will be established when first used. - * - * uint32_t device_id = 32-bit device id of device. Set to HDHOMERUN_DEVICE_ID_WILDCARD to match any device ID. - * uint32_t device_ip = IP address of device. Set to 0 to auto-detect. - * unsigned int tuner = tuner index (0 or 1). Can be changed later by calling hdhomerun_device_set_tuner. - * struct hdhomerun_debug_t *dbg: Pointer to debug logging object. May be NULL. - * - * Returns a pointer to the newly created device object. - * - * When no longer needed, the socket should be destroyed by calling hdhomerun_device_destroy. - * - * The hdhomerun_device_create_from_str function creates a device object from the given device_str. - * The device_str parameter can be any of the following forms: - * - * - - * - * If the tuner index is not included in the device_str then it is set to zero. - * Use hdhomerun_device_set_tuner or hdhomerun_device_set_tuner_from_str to set the tuner. - * - * The hdhomerun_device_set_tuner_from_str function sets the tuner from the given tuner_str. - * The tuner_str parameter can be any of the following forms: - * - * /tuner - */ -extern LIBTYPE struct hdhomerun_device_t *hdhomerun_device_create(uint32_t device_id, uint32_t device_ip, unsigned int tuner, struct hdhomerun_debug_t *dbg); -extern LIBTYPE struct hdhomerun_device_t *hdhomerun_device_create_from_str(const char *device_str, struct hdhomerun_debug_t *dbg); -extern LIBTYPE void hdhomerun_device_destroy(struct hdhomerun_device_t *hd); - -/* - * Get the device id, ip, or tuner of the device instance. - */ -extern LIBTYPE uint32_t hdhomerun_device_get_device_id(struct hdhomerun_device_t *hd); -extern LIBTYPE uint32_t hdhomerun_device_get_device_ip(struct hdhomerun_device_t *hd); -extern LIBTYPE uint32_t hdhomerun_device_get_device_id_requested(struct hdhomerun_device_t *hd); -extern LIBTYPE uint32_t hdhomerun_device_get_device_ip_requested(struct hdhomerun_device_t *hd); -extern LIBTYPE unsigned int hdhomerun_device_get_tuner(struct hdhomerun_device_t *hd); - -extern LIBTYPE void hdhomerun_device_set_device(struct hdhomerun_device_t *hd, uint32_t device_id, uint32_t device_ip); -extern LIBTYPE void hdhomerun_device_set_tuner(struct hdhomerun_device_t *hd, unsigned int tuner); -extern LIBTYPE int hdhomerun_device_set_tuner_from_str(struct hdhomerun_device_t *hd, const char *tuner_str); - -/* - * Get the local machine IP address used when communicating with the device. - * - * This function is useful for determining the IP address to use with set target commands. - * - * Returns 32-bit IP address with native endianness, or 0 on error. - */ -extern LIBTYPE uint32_t hdhomerun_device_get_local_machine_addr(struct hdhomerun_device_t *hd); - -/* - * Get operations. - * - * struct hdhomerun_tuner_status_t *status = Pointer to caller supplied status struct to be populated with result. - * const char **p = Caller supplied char * to be updated to point to the result string. The string will remain - * valid until another call to a device function. - * - * Returns 1 if the operation was successful. - * Returns 0 if the operation was rejected. - * Returns -1 if a communication error occurred. - */ -extern LIBTYPE int hdhomerun_device_get_tuner_status(struct hdhomerun_device_t *hd, char **pstatus_str, struct hdhomerun_tuner_status_t *status); -extern LIBTYPE int hdhomerun_device_get_tuner_streaminfo(struct hdhomerun_device_t *hd, char **pstreaminfo); -extern LIBTYPE int hdhomerun_device_get_tuner_channel(struct hdhomerun_device_t *hd, char **pchannel); -extern LIBTYPE int hdhomerun_device_get_tuner_channelmap(struct hdhomerun_device_t *hd, char **pchannelmap); -extern LIBTYPE int hdhomerun_device_get_tuner_filter(struct hdhomerun_device_t *hd, char **pfilter); -extern LIBTYPE int hdhomerun_device_get_tuner_program(struct hdhomerun_device_t *hd, char **pprogram); -extern LIBTYPE int hdhomerun_device_get_tuner_target(struct hdhomerun_device_t *hd, char **ptarget); -extern LIBTYPE int hdhomerun_device_get_tuner_plotsample(struct hdhomerun_device_t *hd, struct hdhomerun_plotsample_t **psamples, size_t *pcount); -extern LIBTYPE int hdhomerun_device_get_tuner_lockkey_owner(struct hdhomerun_device_t *hd, char **powner); -extern LIBTYPE int hdhomerun_device_get_ir_target(struct hdhomerun_device_t *hd, char **ptarget); -extern LIBTYPE int hdhomerun_device_get_lineup_location(struct hdhomerun_device_t *hd, char **plocation); -extern LIBTYPE int hdhomerun_device_get_version(struct hdhomerun_device_t *hd, char **pversion_str, uint32_t *pversion_num); - -extern LIBTYPE uint32_t hdhomerun_device_get_tuner_status_ss_color(struct hdhomerun_tuner_status_t *status); -extern LIBTYPE uint32_t hdhomerun_device_get_tuner_status_snq_color(struct hdhomerun_tuner_status_t *status); -extern LIBTYPE uint32_t hdhomerun_device_get_tuner_status_seq_color(struct hdhomerun_tuner_status_t *status); - -extern LIBTYPE const char *hdhomerun_device_get_model_str(struct hdhomerun_device_t *hd); - -/* - * Set operations. - * - * const char * = String to send to device. - * - * Returns 1 if the operation was successful. - * Returns 0 if the operation was rejected. - * Returns -1 if a communication error occurred. - */ -extern LIBTYPE int hdhomerun_device_set_tuner_channel(struct hdhomerun_device_t *hd, const char *channel); -extern LIBTYPE int hdhomerun_device_set_tuner_channelmap(struct hdhomerun_device_t *hd, const char *channelmap); -extern LIBTYPE int hdhomerun_device_set_tuner_filter(struct hdhomerun_device_t *hd, const char *filter); -extern LIBTYPE int hdhomerun_device_set_tuner_filter_by_array(struct hdhomerun_device_t *hd, unsigned char filter_array[0x2000]); -extern LIBTYPE int hdhomerun_device_set_tuner_program(struct hdhomerun_device_t *hd, const char *program); -extern LIBTYPE int hdhomerun_device_set_tuner_target(struct hdhomerun_device_t *hd, char *target); -extern LIBTYPE int hdhomerun_device_set_tuner_target_to_local_protocol(struct hdhomerun_device_t *hd, const char *protocol); -extern LIBTYPE int hdhomerun_device_set_tuner_target_to_local(struct hdhomerun_device_t *hd); -extern LIBTYPE int hdhomerun_device_set_ir_target(struct hdhomerun_device_t *hd, const char *target); -extern LIBTYPE int hdhomerun_device_set_lineup_location(struct hdhomerun_device_t *hd, const char *location); - -/* - * Get/set a named control variable on the device. - * - * const char *name: The name of var to get/set (c-string). The supported vars is device/firmware dependant. - * const char *value: The value to set (c-string). The format is device/firmware dependant. - - * char **pvalue: If provided, the caller-supplied char pointer will be populated with a pointer to the value - * string returned by the device, or NULL if the device returned an error string. The string will remain - * valid until the next call to a control sock function. - * char **perror: If provided, the caller-supplied char pointer will be populated with a pointer to the error - * string returned by the device, or NULL if the device returned an value string. The string will remain - * valid until the next call to a control sock function. - * - * Returns 1 if the operation was successful (pvalue set, perror NULL). - * Returns 0 if the operation was rejected (pvalue NULL, perror set). - * Returns -1 if a communication error occurs. - */ -extern LIBTYPE int hdhomerun_device_get_var(struct hdhomerun_device_t *hd, const char *name, char **pvalue, char **perror); -extern LIBTYPE int hdhomerun_device_set_var(struct hdhomerun_device_t *hd, const char *name, const char *value, char **pvalue, char **perror); - -/* - * Tuner locking. - * - * The hdhomerun_device_tuner_lockkey_request function is used to obtain a lock - * or to verify that the hdhomerun_device object still holds the lock. - * Returns 1 if the lock request was successful and the lock was obtained. - * Returns 0 if the lock request was rejected. - * Returns -1 if a communication error occurs. - * - * The hdhomerun_device_tuner_lockkey_release function is used to release a - * previously held lock. If locking is used then this function must be called - * before destroying the hdhomerun_device object. - */ -extern LIBTYPE int hdhomerun_device_tuner_lockkey_request(struct hdhomerun_device_t *hd, char **perror); -extern LIBTYPE int hdhomerun_device_tuner_lockkey_release(struct hdhomerun_device_t *hd); -extern LIBTYPE int hdhomerun_device_tuner_lockkey_force(struct hdhomerun_device_t *hd); - -/* - * Intended only for non persistent connections; eg, hdhomerun_config. - */ -extern LIBTYPE void hdhomerun_device_tuner_lockkey_use_value(struct hdhomerun_device_t *hd, uint32_t lockkey); - -/* - * Wait for tuner lock after channel change. - * - * The hdhomerun_device_wait_for_lock function is used to detect/wait for a lock vs no lock indication - * after a channel change. - * - * It will return quickly if a lock is aquired. - * It will return quickly if there is no signal detected. - * Worst case it will time out after 1.5 seconds - the case where there is signal but no lock. - */ -extern LIBTYPE int hdhomerun_device_wait_for_lock(struct hdhomerun_device_t *hd, struct hdhomerun_tuner_status_t *status); - -/* - * Stream a filtered program or the unfiltered stream. - * - * The hdhomerun_device_stream_start function initializes the process and tells the device to start streamin data. - * - * uint16_t program_number = The program number to filer, or 0 for unfiltered. - * - * Returns 1 if the oprtation started successfully. - * Returns 0 if the operation was rejected. - * Returns -1 if a communication error occurs. - * - * The hdhomerun_device_stream_recv function should be called periodically to receive the stream data. - * The buffer can losslessly store 1 second of data, however a more typical call rate would be every 64ms. - * - * The hdhomerun_device_stream_stop function tells the device to stop streaming data. - */ -extern LIBTYPE int hdhomerun_device_stream_start(struct hdhomerun_device_t *hd); -extern LIBTYPE int hdhomerun_device_stream_refresh_target(struct hdhomerun_device_t *hd); -extern LIBTYPE uint8_t *hdhomerun_device_stream_recv(struct hdhomerun_device_t *hd, size_t max_size, size_t *pactual_size); -extern LIBTYPE void hdhomerun_device_stream_flush(struct hdhomerun_device_t *hd); -extern LIBTYPE void hdhomerun_device_stream_stop(struct hdhomerun_device_t *hd); - -/* - * Channel scan API. - */ -extern LIBTYPE int hdhomerun_device_channelscan_init(struct hdhomerun_device_t *hd, const char *channelmap); -extern LIBTYPE int hdhomerun_device_channelscan_advance(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result); -extern LIBTYPE int hdhomerun_device_channelscan_detect(struct hdhomerun_device_t *hd, struct hdhomerun_channelscan_result_t *result); -extern LIBTYPE uint8_t hdhomerun_device_channelscan_get_progress(struct hdhomerun_device_t *hd); - -/* - * Check that the device is running the recommended firmware. - * - * uint32_t features: Reserved for future use. Set to zero. - * - * Returns 1 if the firmware meets the minimum requriements for all operations. - * Returns 0 if th firmware does not meet the minimum requriements for all operations. - * Returns -1 if an error occurs. - */ -extern LIBTYPE int hdhomerun_device_firmware_version_check(struct hdhomerun_device_t *hd, uint32_t features); - -/* - * Upload new firmware to the device. - * - * FILE *upgrade_file: File pointer to read from. The file must have been opened in binary mode for reading. - * - * Returns 1 if the upload succeeded. - * Returns 0 if the upload was rejected. - * Returns -1 if an error occurs. - */ -extern LIBTYPE int hdhomerun_device_upgrade(struct hdhomerun_device_t *hd, FILE *upgrade_file); - -/* - * Low level accessor functions. - */ -extern LIBTYPE struct hdhomerun_control_sock_t *hdhomerun_device_get_control_sock(struct hdhomerun_device_t *hd); -extern LIBTYPE struct hdhomerun_video_sock_t *hdhomerun_device_get_video_sock(struct hdhomerun_device_t *hd); - -/* - * Debug print internal stats. - */ -extern LIBTYPE void hdhomerun_device_debug_print_video_stats(struct hdhomerun_device_t *hd); -extern LIBTYPE void hdhomerun_device_get_video_stats(struct hdhomerun_device_t *hd, struct hdhomerun_video_stats_t *stats); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_dhcp.c b/lib/libhdhomerun/hdhomerun_dhcp.c deleted file mode 100644 index 49cb09c200ff9..0000000000000 --- a/lib/libhdhomerun/hdhomerun_dhcp.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * hdhomerun_dhcp.c - * - * Copyright © 2006-2007 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" -#include "hdhomerun_dhcp.h" - -struct dhcp_hdr_t { - uint8_t bootp_message_type; - uint8_t hardware_type; - uint8_t hardware_address_length; - uint8_t hops; - uint32_t transaction_id; - uint16_t seconds_elapsed; - uint16_t bootp_flags; - uint32_t client_ip; - uint32_t your_ip; - uint32_t next_server_ip; - uint32_t relay_agent_ip; - uint8_t client_mac[16]; - uint8_t server_host_name[64]; - uint8_t boot_file_name[128]; - uint32_t magic_cookie; -}; - -struct hdhomerun_dhcp_t { - int sock; - uint32_t local_address; - pthread_t thread; - volatile bool_t terminate; -}; - -static THREAD_FUNC_PREFIX hdhomerun_dhcp_thread_execute(void *arg); - -struct hdhomerun_dhcp_t *hdhomerun_dhcp_create(uint32_t bind_address) -{ - if (bind_address != 0) { - if ((bind_address & 0xFFFF0000) != 0xA9FE0000) { - return NULL; - } - } - - /* Create socket. */ - int sock = (int)socket(AF_INET, SOCK_DGRAM, 0); - if (sock == -1) { - return NULL; - } - - /* Set timeout. */ - setsocktimeout(sock, SOL_SOCKET, SO_RCVTIMEO, 1000); - - /* Allow broadcast. */ - int sock_opt = 1; - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&sock_opt, sizeof(sock_opt)); - - /* Allow reuse. */ - sock_opt = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&sock_opt, sizeof(sock_opt)); - - /* Bind socket. */ - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(bind_address); - sock_addr.sin_port = htons(67); - if (bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) { - close(sock); - return NULL; - } - - /* Allocate object. */ - struct hdhomerun_dhcp_t *dhcp = (struct hdhomerun_dhcp_t *)calloc(1, sizeof(struct hdhomerun_dhcp_t)); - if (!dhcp) { - close(sock); - return NULL; - } - - dhcp->sock = sock; - - if (bind_address != 0) { - dhcp->local_address = bind_address; - } else { - dhcp->local_address = 0xA9FEFFFF; - } - - /* Spawn thread. */ - if (pthread_create(&dhcp->thread, NULL, &hdhomerun_dhcp_thread_execute, dhcp) != 0) { - close(sock); - free(dhcp); - return NULL; - } - - /* Success. */ - return dhcp; -} - -void hdhomerun_dhcp_destroy(struct hdhomerun_dhcp_t *dhcp) -{ - dhcp->terminate = TRUE; - pthread_join(dhcp->thread, NULL); - - close(dhcp->sock); - free(dhcp); -} - -static void hdhomerun_dhcp_send(struct hdhomerun_dhcp_t *dhcp, uint8_t message_type, struct hdhomerun_pkt_t *pkt) -{ - pkt->pos = pkt->start; - struct dhcp_hdr_t *hdr = (struct dhcp_hdr_t *)pkt->pos; - pkt->pos += sizeof(struct dhcp_hdr_t); - pkt->end = pkt->pos; - - uint32_t remote_addr = 0xA9FE0000; - remote_addr |= (uint32_t)hdr->client_mac[4] << 8; - remote_addr |= (uint32_t)hdr->client_mac[5] << 0; - if ((remote_addr == 0xA9FE0000) || (remote_addr == 0xA9FEFFFF)) { - remote_addr = 0xA9FE8080; - } - - hdr->bootp_message_type = 0x02; - hdr->your_ip = htonl(remote_addr); - hdr->next_server_ip = htonl(0x00000000); - - hdhomerun_pkt_write_u8(pkt, 53); - hdhomerun_pkt_write_u8(pkt, 1); - hdhomerun_pkt_write_u8(pkt, message_type); - - hdhomerun_pkt_write_u8(pkt, 54); - hdhomerun_pkt_write_u8(pkt, 4); - hdhomerun_pkt_write_u32(pkt, dhcp->local_address); - - hdhomerun_pkt_write_u8(pkt, 51); - hdhomerun_pkt_write_u8(pkt, 4); - hdhomerun_pkt_write_u32(pkt, 7*24*60*60); - - hdhomerun_pkt_write_u8(pkt, 1); - hdhomerun_pkt_write_u8(pkt, 4); - hdhomerun_pkt_write_u32(pkt, 0xFFFF0000); - - hdhomerun_pkt_write_u8(pkt, 0xFF); - - while (pkt->pos < pkt->start + 300) { - hdhomerun_pkt_write_u8(pkt, 0x00); - } - - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(0xFFFFFFFF); - sock_addr.sin_port = htons(68); - - sendto(dhcp->sock, (char *)pkt->start, (int)(pkt->end - pkt->start), 0, (struct sockaddr *)&sock_addr, sizeof(sock_addr)); -} - -static void hdhomerun_dhcp_recv(struct hdhomerun_dhcp_t *dhcp, struct hdhomerun_pkt_t *pkt) -{ - pkt->pos = pkt->start; - struct dhcp_hdr_t *hdr = (struct dhcp_hdr_t *)pkt->pos; - pkt->pos += sizeof(struct dhcp_hdr_t); - if (pkt->pos > pkt->end) { - return; - } - - if (ntohl(hdr->magic_cookie) != 0x63825363) { - return; - } - - static uint8_t vendor[3] = {0x00, 0x18, 0xDD}; - if (memcmp(hdr->client_mac, vendor, 3) != 0) { - return; - } - - if (pkt->pos + 3 > pkt->end) { - return; - } - if (hdhomerun_pkt_read_u8(pkt) != 53) { - return; - } - if (hdhomerun_pkt_read_u8(pkt) != 1) { - return; - } - uint8_t message_type_val = hdhomerun_pkt_read_u8(pkt); - - switch (message_type_val) { - case 0x01: - hdhomerun_dhcp_send(dhcp, 0x02, pkt); - break; - case 0x03: - hdhomerun_dhcp_send(dhcp, 0x05, pkt); - break; - default: - return; - } -} - -static THREAD_FUNC_PREFIX hdhomerun_dhcp_thread_execute(void *arg) -{ - struct hdhomerun_dhcp_t *dhcp = (struct hdhomerun_dhcp_t *)arg; - struct hdhomerun_pkt_t pkt_inst; - - while (1) { - if (dhcp->terminate) { - return NULL; - } - - struct hdhomerun_pkt_t *pkt = &pkt_inst; - hdhomerun_pkt_reset(pkt); - - int rx_length = recv(dhcp->sock, (char *)pkt->end, (int)(pkt->limit - pkt->end), 0); - if (rx_length <= 0) { - if (!sock_getlasterror_socktimeout) { - sleep(1); - } - continue; - } - pkt->end += rx_length; - - hdhomerun_dhcp_recv(dhcp, pkt); - } -} diff --git a/lib/libhdhomerun/hdhomerun_dhcp.h b/lib/libhdhomerun/hdhomerun_dhcp.h deleted file mode 100644 index 43df9f38f57f1..0000000000000 --- a/lib/libhdhomerun/hdhomerun_dhcp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * hdhomerun_dhcp.h - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_dhcp_t; - -extern LIBTYPE struct hdhomerun_dhcp_t *hdhomerun_dhcp_create(uint32_t bind_address); -extern LIBTYPE void hdhomerun_dhcp_destroy(struct hdhomerun_dhcp_t *dhcp); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_discover.c b/lib/libhdhomerun/hdhomerun_discover.c deleted file mode 100644 index 25ee44b553ebc..0000000000000 --- a/lib/libhdhomerun/hdhomerun_discover.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - * hdhomerun_discover.c - * - * Copyright © 2006-2007 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -#if defined(__CYGWIN__) || defined(__WINDOWS__) -#include -#include -#define USE_IPHLPAPI 1 -#else -#include -#include -#ifndef _SIZEOF_ADDR_IFREQ -#define _SIZEOF_ADDR_IFREQ(x) sizeof(x) -#endif -#endif - -#define HDHOMERUN_DISOCVER_MAX_SOCK_COUNT 16 - -struct hdhomerun_discover_sock_t { - int sock; - uint32_t local_ip; - uint32_t subnet_mask; -}; - -struct hdhomerun_discover_t { - struct hdhomerun_discover_sock_t socks[HDHOMERUN_DISOCVER_MAX_SOCK_COUNT]; - unsigned int sock_count; - struct hdhomerun_pkt_t tx_pkt; - struct hdhomerun_pkt_t rx_pkt; -}; - -static bool_t hdhomerun_discover_sock_create(struct hdhomerun_discover_t *ds, uint32_t local_ip, uint32_t subnet_mask) -{ - if (ds->sock_count >= HDHOMERUN_DISOCVER_MAX_SOCK_COUNT) { - return FALSE; - } - - /* Create socket. */ - int sock = (int)socket(AF_INET, SOCK_DGRAM, 0); - if (sock == -1) { - return FALSE; - } - - /* Set timeouts. */ - setsocktimeout(sock, SOL_SOCKET, SO_SNDTIMEO, 1000); - setsocktimeout(sock, SOL_SOCKET, SO_RCVTIMEO, 1000); - - /* Allow broadcast. */ - int sock_opt = 1; - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&sock_opt, sizeof(sock_opt)); - - /* Bind socket. */ - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(local_ip); - sock_addr.sin_port = htons(0); - if (bind(sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) { - close(sock); - return FALSE; - } - - /* Write sock entry. */ - struct hdhomerun_discover_sock_t *dss = &ds->socks[ds->sock_count++]; - dss->sock = sock; - dss->local_ip = local_ip; - dss->subnet_mask = subnet_mask; - - return TRUE; -} - -#if defined(USE_IPHLPAPI) -static void hdhomerun_discover_sock_detect(struct hdhomerun_discover_t *ds) -{ - PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO)); - ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO); - - DWORD Ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); - if (Ret != NO_ERROR) { - free(pAdapterInfo); - if (Ret != ERROR_BUFFER_OVERFLOW) { - return; - } - pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); - Ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); - if (Ret != NO_ERROR) { - free(pAdapterInfo); - return; - } - } - - PIP_ADAPTER_INFO pAdapter = pAdapterInfo; - while (pAdapter) { - IP_ADDR_STRING *pIPAddr = &pAdapter->IpAddressList; - while (pIPAddr) { - uint32_t local_ip = ntohl(inet_addr(pIPAddr->IpAddress.String)); - uint32_t mask = ntohl(inet_addr(pIPAddr->IpMask.String)); - - if (local_ip == 0) { - pIPAddr = pIPAddr->Next; - continue; - } - - hdhomerun_discover_sock_create(ds, local_ip, mask); - pIPAddr = pIPAddr->Next; - } - - pAdapter = pAdapter->Next; - } - - free(pAdapterInfo); -} - -#else - -static void hdhomerun_discover_sock_detect(struct hdhomerun_discover_t *ds) -{ - int fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd == -1) { - return; - } - - struct ifconf ifc; - uint8_t buf[8192]; - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = (char *)buf; - - memset(buf, 0, sizeof(buf)); - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return; - } - - uint8_t *ptr = (uint8_t *)ifc.ifc_req; - uint8_t *end = (uint8_t *)&ifc.ifc_buf[ifc.ifc_len]; - - while (ptr <= end) { - struct ifreq *ifr = (struct ifreq *)ptr; - ptr += _SIZEOF_ADDR_IFREQ(*ifr); - - if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { - continue; - } - struct sockaddr_in *addr_in = (struct sockaddr_in *)&(ifr->ifr_addr); - uint32_t local_ip = ntohl(addr_in->sin_addr.s_addr); - if (local_ip == 0) { - continue; - } - - if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { - continue; - } - struct sockaddr_in *mask_in = (struct sockaddr_in *)&(ifr->ifr_addr); - uint32_t mask = ntohl(mask_in->sin_addr.s_addr); - - hdhomerun_discover_sock_create(ds, local_ip, mask); - } -} -#endif - -static struct hdhomerun_discover_t *hdhomerun_discover_create(void) -{ - struct hdhomerun_discover_t *ds = (struct hdhomerun_discover_t *)calloc(1, sizeof(struct hdhomerun_discover_t)); - if (!ds) { - return NULL; - } - - /* Create a routable socket. */ - if (!hdhomerun_discover_sock_create(ds, 0, 0)) { - free(ds); - return NULL; - } - - /* Detect & create local sockets. */ - hdhomerun_discover_sock_detect(ds); - - /* Success. */ - return ds; -} - -static void hdhomerun_discover_destroy(struct hdhomerun_discover_t *ds) -{ - unsigned int i; - for (i = 0; i < ds->sock_count; i++) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; - close(dss->sock); - } - - free(ds); -} - -static bool_t hdhomerun_discover_send_internal(struct hdhomerun_discover_t *ds, struct hdhomerun_discover_sock_t *dss, uint32_t target_ip, uint32_t device_type, uint32_t device_id) -{ - struct hdhomerun_pkt_t *tx_pkt = &ds->tx_pkt; - hdhomerun_pkt_reset(tx_pkt); - - hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_DEVICE_TYPE); - hdhomerun_pkt_write_var_length(tx_pkt, 4); - hdhomerun_pkt_write_u32(tx_pkt, device_type); - hdhomerun_pkt_write_u8(tx_pkt, HDHOMERUN_TAG_DEVICE_ID); - hdhomerun_pkt_write_var_length(tx_pkt, 4); - hdhomerun_pkt_write_u32(tx_pkt, device_id); - hdhomerun_pkt_seal_frame(tx_pkt, HDHOMERUN_TYPE_DISCOVER_REQ); - - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(target_ip); - sock_addr.sin_port = htons(HDHOMERUN_DISCOVER_UDP_PORT); - - int length = (int)(tx_pkt->end - tx_pkt->start); - if (sendto(dss->sock, (char *)tx_pkt->start, length, 0, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != length) { - return FALSE; - } - - return TRUE; -} - -static bool_t hdhomerun_discover_send_wildcard_ip(struct hdhomerun_discover_t *ds, uint32_t device_type, uint32_t device_id) -{ - bool_t result = FALSE; - - /* - * Send subnet broadcast using each local ip socket. - * This will work with multiple separate 169.254.x.x interfaces. - */ - unsigned int i; - for (i = 1; i < ds->sock_count; i++) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; - uint32_t target_ip = dss->local_ip | ~dss->subnet_mask; - result |= hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id); - } - - /* - * If no local ip sockets then fall back to sending a global broadcast letting the OS choose the interface. - */ - if (!result) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[0]; - result = hdhomerun_discover_send_internal(ds, dss, 0xFFFFFFFF, device_type, device_id); - } - - return result; -} - -static bool_t hdhomerun_discover_send_target_ip(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id) -{ - bool_t result = FALSE; - - /* - * Send targeted packet from any local ip that is in the same subnet. - * This will work with multiple separate 169.254.x.x interfaces. - */ - unsigned int i; - for (i = 1; i < ds->sock_count; i++) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; - if ((target_ip & dss->subnet_mask) != (dss->local_ip & dss->subnet_mask)) { - continue; - } - - result |= hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id); - } - - /* - * If target IP does not match a local subnet then fall back to letting the OS choose the gateway interface. - */ - if (!result) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[0]; - result = hdhomerun_discover_send_internal(ds, dss, target_ip, device_type, device_id); - } - - return result; -} - -static bool_t hdhomerun_discover_send(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id) -{ - if (target_ip != 0) { - return hdhomerun_discover_send_target_ip(ds, target_ip, device_type, device_id); - } - - return hdhomerun_discover_send_wildcard_ip(ds, device_type, device_id); -} - -static int hdhomerun_discover_recv_internal(struct hdhomerun_discover_t *ds, struct hdhomerun_discover_sock_t *dss, struct hdhomerun_discover_device_t *result) -{ - struct hdhomerun_pkt_t *rx_pkt = &ds->rx_pkt; - hdhomerun_pkt_reset(rx_pkt); - - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - socklen_t sockaddr_size = sizeof(sock_addr); - - int rx_length = recvfrom(dss->sock, (char *)rx_pkt->end, (int)(rx_pkt->limit - rx_pkt->end), 0, (struct sockaddr *)&sock_addr, &sockaddr_size); - if (rx_length <= 0) { - /* Don't return error - windows machine on VPN can sometimes cause a sock error here but otherwise works. */ - return 0; - } - rx_pkt->end += rx_length; - - uint16_t type; - if (hdhomerun_pkt_open_frame(rx_pkt, &type) <= 0) { - return 0; - } - if (type != HDHOMERUN_TYPE_DISCOVER_RPY) { - return 0; - } - - result->ip_addr = ntohl(sock_addr.sin_addr.s_addr); - result->device_type = 0; - result->device_id = 0; - - while (1) { - uint8_t tag; - size_t len; - uint8_t *next = hdhomerun_pkt_read_tlv(rx_pkt, &tag, &len); - if (!next) { - break; - } - - switch (tag) { - case HDHOMERUN_TAG_DEVICE_TYPE: - if (len != 4) { - break; - } - result->device_type = hdhomerun_pkt_read_u32(rx_pkt); - break; - - case HDHOMERUN_TAG_DEVICE_ID: - if (len != 4) { - break; - } - result->device_id = hdhomerun_pkt_read_u32(rx_pkt); - break; - - default: - break; - } - - rx_pkt->pos = next; - } - - return 1; -} - -static int hdhomerun_discover_recv(struct hdhomerun_discover_t *ds, struct hdhomerun_discover_device_t *result) -{ - struct timeval t; - t.tv_sec = 0; - t.tv_usec = 250000; - - fd_set readfds; - FD_ZERO(&readfds); - int max_sock = -1; - - unsigned int i; - for (i = 0; i < ds->sock_count; i++) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; - FD_SET(dss->sock, &readfds); - if (dss->sock > max_sock) { - max_sock = dss->sock; - } - } - - if (select(max_sock+1, &readfds, NULL, NULL, &t) < 0) { - return -1; - } - - for (i = 0; i < ds->sock_count; i++) { - struct hdhomerun_discover_sock_t *dss = &ds->socks[i]; - if (!FD_ISSET(dss->sock, &readfds)) { - continue; - } - - if (hdhomerun_discover_recv_internal(ds, dss, result) <= 0) { - continue; - } - - return 1; - } - - return 0; -} - -static struct hdhomerun_discover_device_t *hdhomerun_discover_find_in_list(struct hdhomerun_discover_device_t result_list[], int count, uint32_t ip_addr) -{ - int index; - for (index = 0; index < count; index++) { - struct hdhomerun_discover_device_t *result = &result_list[index]; - if (result->ip_addr == ip_addr) { - return result; - } - } - - return NULL; -} - -static int hdhomerun_discover_find_devices_internal(struct hdhomerun_discover_t *ds, uint32_t target_ip, uint32_t device_type, uint32_t device_id, struct hdhomerun_discover_device_t result_list[], int max_count) -{ - int count = 0; - int attempt; - for (attempt = 0; attempt < 4; attempt++) { - if (!hdhomerun_discover_send(ds, target_ip, device_type, device_id)) { - return -1; - } - - uint64_t timeout = getcurrenttime() + 250; - while (getcurrenttime() < timeout) { - struct hdhomerun_discover_device_t *result = &result_list[count]; - - int ret = hdhomerun_discover_recv(ds, result); - if (ret < 0) { - return -1; - } - if (ret == 0) { - continue; - } - - /* Filter. */ - if (device_type != HDHOMERUN_DEVICE_TYPE_WILDCARD) { - if (device_type != result->device_type) { - continue; - } - } - if (device_id != HDHOMERUN_DEVICE_ID_WILDCARD) { - if (device_id != result->device_id) { - continue; - } - } - - /* Ensure not already in list. */ - if (hdhomerun_discover_find_in_list(result_list, count, result->ip_addr)) { - continue; - } - - /* Add to list. */ - count++; - if (count >= max_count) { - return count; - } - } - } - - return count; -} - -int hdhomerun_discover_find_devices_custom(uint32_t target_ip, uint32_t device_type, uint32_t device_id, struct hdhomerun_discover_device_t result_list[], int max_count) -{ - struct hdhomerun_discover_t *ds = hdhomerun_discover_create(); - if (!ds) { - return -1; - } - - int ret = hdhomerun_discover_find_devices_internal(ds, target_ip, device_type, device_id, result_list, max_count); - - hdhomerun_discover_destroy(ds); - return ret; -} - -bool_t hdhomerun_discover_validate_device_id(uint32_t device_id) -{ - static uint32_t lookup_table[16] = {0xA, 0x5, 0xF, 0x6, 0x7, 0xC, 0x1, 0xB, 0x9, 0x2, 0x8, 0xD, 0x4, 0x3, 0xE, 0x0}; - - uint32_t checksum = 0; - - checksum ^= lookup_table[(device_id >> 28) & 0x0F]; - checksum ^= (device_id >> 24) & 0x0F; - checksum ^= lookup_table[(device_id >> 20) & 0x0F]; - checksum ^= (device_id >> 16) & 0x0F; - checksum ^= lookup_table[(device_id >> 12) & 0x0F]; - checksum ^= (device_id >> 8) & 0x0F; - checksum ^= lookup_table[(device_id >> 4) & 0x0F]; - checksum ^= (device_id >> 0) & 0x0F; - - return (checksum == 0); -} - diff --git a/lib/libhdhomerun/hdhomerun_discover.h b/lib/libhdhomerun/hdhomerun_discover.h deleted file mode 100644 index 85815bee84418..0000000000000 --- a/lib/libhdhomerun/hdhomerun_discover.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * hdhomerun_discover.h - * - * Copyright © 2006-2007 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_discover_device_t { - uint32_t ip_addr; - uint32_t device_type; - uint32_t device_id; -}; - -/* - * Find devices. - * - * The device information is stored in caller-supplied array of hdhomerun_discover_device_t vars. - * Multiple attempts are made to find devices. - * Execution time is 1 second. - * - * Set target_ip to zero to auto-detect IP address. - * - * Returns the number of devices found. - * Retruns -1 on error. - */ -extern LIBTYPE int hdhomerun_discover_find_devices_custom(uint32_t target_ip, uint32_t device_type, uint32_t device_id, struct hdhomerun_discover_device_t result_list[], int max_count); - -/* - * Verify that the device ID given is valid. - * - * The device ID contains a self-check sequence that detects common user input errors including - * single-digit errors and two digit transposition errors. - * - * Returns TRUE if valid. - * Returns FALSE if not valid. - */ -extern LIBTYPE bool_t hdhomerun_discover_validate_device_id(uint32_t device_id); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_os.h b/lib/libhdhomerun/hdhomerun_os.h deleted file mode 100644 index 9bb438a90d514..0000000000000 --- a/lib/libhdhomerun/hdhomerun_os.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * hdhomerun_os.h - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#if defined(_WIN32) || defined(_WIN64) -#define __WINDOWS__ -#endif - -#if defined(__WINDOWS__) -#include "hdhomerun_os_windows.h" -#else -#include "hdhomerun_os_posix.h" -#endif - -#if !defined(TRUE) -#define TRUE 1 -#endif - -#if !defined(FALSE) -#define FALSE 0 -#endif diff --git a/lib/libhdhomerun/hdhomerun_os_posix.h b/lib/libhdhomerun/hdhomerun_os_posix.h deleted file mode 100644 index c68ecce53a4a8..0000000000000 --- a/lib/libhdhomerun/hdhomerun_os_posix.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * hdhomerun_os_posix.h - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#define _FILE_OFFSET_BITS 64 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(__ANDROID__) -#include -#else -#include -#endif -#include -#include -#include -#include - -typedef int bool_t; - -#define LIBTYPE -#define sock_getlasterror errno -#define sock_getlasterror_socktimeout (errno == EAGAIN) -#define console_vprintf vprintf -#define console_printf printf -#define THREAD_FUNC_PREFIX void * - -static inline int msleep(unsigned int ms) -{ - usleep(ms * 1000); - return 0; -} - -static inline uint64_t getcurrenttime(void) -{ - struct timeval t; - gettimeofday(&t, NULL); - return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000); -} - -static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout) -{ - struct timeval t; - t.tv_sec = timeout / 1000; - t.tv_usec = (timeout % 1000) * 1000; - return setsockopt(s, level, optname, (char *)&t, sizeof(t)); -} - -#define min(a,b) (((a)<(b))?(a):(b)) -#define max(a,b) (((a)>(b))?(a):(b)) - diff --git a/lib/libhdhomerun/hdhomerun_os_windows.h b/lib/libhdhomerun/hdhomerun_os_windows.h deleted file mode 100644 index e484d184831b9..0000000000000 --- a/lib/libhdhomerun/hdhomerun_os_windows.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * hdhomerun_os_windows.h - * - * Copyright © 2006-2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#define _WINSOCKAPI_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __MINGW__ -extern -int WSAAPI getaddrinfo( - const char *nodename, - const char *servname, - const struct addrinfo *hints, - struct addrinfo **res -); - -extern -void WSAAPI freeaddrinfo( - struct addrinfo *ai -); -#else -#include -#endif - - -#if defined(DLL_EXPORT) -#define LIBTYPE __declspec( dllexport ) -#elif defined(DLL_IMPORT) -#define LIBTYPE __declspec( dllimport ) -#else -#define LIBTYPE -#endif - -typedef int bool_t; -typedef signed __int8 int8_t; -typedef signed __int16 int16_t; -typedef signed __int32 int32_t; -typedef signed __int64 int64_t; -typedef unsigned __int8 uint8_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -typedef HANDLE pthread_t; -typedef HANDLE pthread_mutex_t; - -#define socklen_t int -#define close closesocket -#define sock_getlasterror WSAGetLastError() -#define sock_getlasterror_socktimeout (WSAGetLastError() == WSAETIMEDOUT) -#ifndef va_copy -#define va_copy(x, y) x = y -#endif -#define atoll _atoi64 -#define strdup _strdup -#ifndef strcasecmp -#define strcasecmp _stricmp -#endif -#define snprintf _snprintf -#define fseeko _fseeki64 -#define ftello _ftelli64 -#define THREAD_FUNC_PREFIX DWORD WINAPI -#define SIGPIPE SIGABRT - -static inline int msleep(unsigned int ms) -{ - Sleep(ms); - return 0; -} - -static inline int sleep(unsigned int sec) -{ - Sleep(sec * 1000); - return 0; -} - -static inline uint64_t getcurrenttime(void) -{ - struct timeb tb; - ftime(&tb); - return ((uint64_t)tb.time * 1000) + tb.millitm; -} - -static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout) -{ - int t = (int)timeout; - return setsockopt(s, level, optname, (char *)&t, sizeof(t)); -} - -static inline int pthread_create(pthread_t *tid, void *attr, LPTHREAD_START_ROUTINE start, void *arg) -{ - *tid = CreateThread(NULL, 0, start, arg, 0, NULL); - if (!*tid) { - return (int)GetLastError(); - } - return 0; -} - -static inline int pthread_join(pthread_t tid, void **value_ptr) -{ - while (1) { - DWORD ExitCode = 0; - if (!GetExitCodeThread(tid, &ExitCode)) { - return (int)GetLastError(); - } - if (ExitCode != STILL_ACTIVE) { - return 0; - } - } -} - -static inline void pthread_mutex_init(pthread_mutex_t *mutex, void *attr) -{ - *mutex = CreateMutex(NULL, FALSE, NULL); -} - -static inline void pthread_mutex_lock(pthread_mutex_t *mutex) -{ - WaitForSingleObject(*mutex, INFINITE); -} - -static inline void pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - ReleaseMutex(*mutex); -} - -/* - * The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing. - * Attempting to restore on exit fails to restore if the program is terminated by the user. - * Solution - set the output format each printf. - */ -static inline void console_vprintf(const char *fmt, va_list ap) -{ - UINT cp = GetConsoleOutputCP(); - SetConsoleOutputCP(CP_UTF8); - vprintf(fmt, ap); - SetConsoleOutputCP(cp); -} - -static inline void console_printf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - console_vprintf(fmt, ap); - va_end(ap); -} diff --git a/lib/libhdhomerun/hdhomerun_pkt.c b/lib/libhdhomerun/hdhomerun_pkt.c deleted file mode 100644 index 91c72390c1a21..0000000000000 --- a/lib/libhdhomerun/hdhomerun_pkt.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * hdhomerun_pkt.c - * - * Copyright © 2005-2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -struct hdhomerun_pkt_t *hdhomerun_pkt_create(void) -{ - struct hdhomerun_pkt_t *pkt = (struct hdhomerun_pkt_t *)calloc(1, sizeof(struct hdhomerun_pkt_t)); - if (!pkt) { - return NULL; - } - - hdhomerun_pkt_reset(pkt); - - return pkt; -} - -void hdhomerun_pkt_destroy(struct hdhomerun_pkt_t *pkt) -{ - free(pkt); -} - -void hdhomerun_pkt_reset(struct hdhomerun_pkt_t *pkt) -{ - pkt->limit = pkt->buffer + sizeof(pkt->buffer) - 4; - pkt->start = pkt->buffer + 1024; - pkt->end = pkt->start; - pkt->pos = pkt->start; -} - -static uint32_t hdhomerun_pkt_calc_crc(uint8_t *start, uint8_t *end) -{ - uint8_t *pos = start; - uint32_t crc = 0xFFFFFFFF; - while (pos < end) { - uint8_t x = (uint8_t)(crc) ^ *pos++; - crc >>= 8; - if (x & 0x01) crc ^= 0x77073096; - if (x & 0x02) crc ^= 0xEE0E612C; - if (x & 0x04) crc ^= 0x076DC419; - if (x & 0x08) crc ^= 0x0EDB8832; - if (x & 0x10) crc ^= 0x1DB71064; - if (x & 0x20) crc ^= 0x3B6E20C8; - if (x & 0x40) crc ^= 0x76DC4190; - if (x & 0x80) crc ^= 0xEDB88320; - } - return crc ^ 0xFFFFFFFF; -} - -uint8_t hdhomerun_pkt_read_u8(struct hdhomerun_pkt_t *pkt) -{ - uint8_t v = *pkt->pos++; - return v; -} - -uint16_t hdhomerun_pkt_read_u16(struct hdhomerun_pkt_t *pkt) -{ - uint16_t v; - v = (uint16_t)*pkt->pos++ << 8; - v |= (uint16_t)*pkt->pos++ << 0; - return v; -} - -uint32_t hdhomerun_pkt_read_u32(struct hdhomerun_pkt_t *pkt) -{ - uint32_t v; - v = (uint32_t)*pkt->pos++ << 24; - v |= (uint32_t)*pkt->pos++ << 16; - v |= (uint32_t)*pkt->pos++ << 8; - v |= (uint32_t)*pkt->pos++ << 0; - return v; -} - -size_t hdhomerun_pkt_read_var_length(struct hdhomerun_pkt_t *pkt) -{ - size_t length; - - if (pkt->pos + 1 > pkt->end) { - return (size_t)-1; - } - - length = (size_t)*pkt->pos++; - if (length & 0x0080) { - if (pkt->pos + 1 > pkt->end) { - return (size_t)-1; - } - - length &= 0x007F; - length |= (size_t)*pkt->pos++ << 7; - } - - return length; -} - -uint8_t *hdhomerun_pkt_read_tlv(struct hdhomerun_pkt_t *pkt, uint8_t *ptag, size_t *plength) -{ - if (pkt->pos + 2 > pkt->end) { - return NULL; - } - - *ptag = hdhomerun_pkt_read_u8(pkt); - *plength = hdhomerun_pkt_read_var_length(pkt); - - if (pkt->pos + *plength > pkt->end) { - return NULL; - } - - return pkt->pos + *plength; -} - -void hdhomerun_pkt_write_u8(struct hdhomerun_pkt_t *pkt, uint8_t v) -{ - *pkt->pos++ = v; - - if (pkt->pos > pkt->end) { - pkt->end = pkt->pos; - } -} - -void hdhomerun_pkt_write_u16(struct hdhomerun_pkt_t *pkt, uint16_t v) -{ - *pkt->pos++ = (uint8_t)(v >> 8); - *pkt->pos++ = (uint8_t)(v >> 0); - - if (pkt->pos > pkt->end) { - pkt->end = pkt->pos; - } -} - -void hdhomerun_pkt_write_u32(struct hdhomerun_pkt_t *pkt, uint32_t v) -{ - *pkt->pos++ = (uint8_t)(v >> 24); - *pkt->pos++ = (uint8_t)(v >> 16); - *pkt->pos++ = (uint8_t)(v >> 8); - *pkt->pos++ = (uint8_t)(v >> 0); - - if (pkt->pos > pkt->end) { - pkt->end = pkt->pos; - } -} - -void hdhomerun_pkt_write_var_length(struct hdhomerun_pkt_t *pkt, size_t v) -{ - if (v <= 127) { - *pkt->pos++ = (uint8_t)v; - } else { - *pkt->pos++ = (uint8_t)(v | 0x80); - *pkt->pos++ = (uint8_t)(v >> 7); - } - - if (pkt->pos > pkt->end) { - pkt->end = pkt->pos; - } -} - -void hdhomerun_pkt_write_mem(struct hdhomerun_pkt_t *pkt, const void *mem, size_t length) -{ - memcpy(pkt->pos, mem, length); - pkt->pos += length; - - if (pkt->pos > pkt->end) { - pkt->end = pkt->pos; - } -} - -int hdhomerun_pkt_open_frame(struct hdhomerun_pkt_t *pkt, uint16_t *ptype) -{ - pkt->pos = pkt->start; - - if (pkt->pos + 4 > pkt->end) { - return 0; - } - - *ptype = hdhomerun_pkt_read_u16(pkt); - size_t length = hdhomerun_pkt_read_u16(pkt); - pkt->pos += length; - - if (pkt->pos + 4 > pkt->end) { - pkt->pos = pkt->start; - return 0; - } - - uint32_t calc_crc = hdhomerun_pkt_calc_crc(pkt->start, pkt->pos); - - uint32_t packet_crc; - packet_crc = (uint32_t)*pkt->pos++ << 0; - packet_crc |= (uint32_t)*pkt->pos++ << 8; - packet_crc |= (uint32_t)*pkt->pos++ << 16; - packet_crc |= (uint32_t)*pkt->pos++ << 24; - if (calc_crc != packet_crc) { - return -1; - } - - pkt->start += 4; - pkt->end = pkt->start + length; - pkt->pos = pkt->start; - return 1; -} - -void hdhomerun_pkt_seal_frame(struct hdhomerun_pkt_t *pkt, uint16_t frame_type) -{ - size_t length = pkt->end - pkt->start; - - pkt->start -= 4; - pkt->pos = pkt->start; - hdhomerun_pkt_write_u16(pkt, frame_type); - hdhomerun_pkt_write_u16(pkt, (uint16_t)length); - - uint32_t crc = hdhomerun_pkt_calc_crc(pkt->start, pkt->end); - *pkt->end++ = (uint8_t)(crc >> 0); - *pkt->end++ = (uint8_t)(crc >> 8); - *pkt->end++ = (uint8_t)(crc >> 16); - *pkt->end++ = (uint8_t)(crc >> 24); - - pkt->pos = pkt->start; -} diff --git a/lib/libhdhomerun/hdhomerun_pkt.h b/lib/libhdhomerun/hdhomerun_pkt.h deleted file mode 100644 index 636a784f09e3b..0000000000000 --- a/lib/libhdhomerun/hdhomerun_pkt.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * hdhomerun_pkt.h - * - * Copyright © 2005-2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ -#ifdef __cplusplus -extern "C" { -#endif - -/* - * The discover protocol (UDP port 65001) and control protocol (TCP port 65001) - * both use the same packet based format: - * uint16_t Packet type - * uint16_t Payload length (bytes) - * uint8_t[] Payload data (0-n bytes). - * uint32_t CRC (Ethernet style 32-bit CRC) - * - * All variables are big-endian except for the crc which is little-endian. - * - * Valid values for the packet type are listed below as defines prefixed - * with "HDHOMERUN_TYPE_" - * - * Discovery: - * - * The payload for a discovery request or reply is a simple sequence of - * tag-length-value data: - * uint8_t Tag - * varlen Length - * uint8_t[] Value (0-n bytes) - * - * The length field can be one or two bytes long. - * For a length <= 127 bytes the length is expressed as a single byte. The - * most-significant-bit is clear indicating a single-byte length. - * For a length >= 128 bytes the length is expressed as a sequence of two bytes as follows: - * The first byte is contains the least-significant 7-bits of the length. The - * most-significant bit is then set (add 0x80) to indicate that it is a two byte length. - * The second byte contains the length shifted down 7 bits. - * - * A discovery request packet has a packet type of HDHOMERUN_TYPE_DISCOVER_REQ and should - * contain two tags: HDHOMERUN_TAG_DEVICE_TYPE and HDHOMERUN_TAG_DEVICE_ID. - * The HDHOMERUN_TAG_DEVICE_TYPE value should be set to HDHOMERUN_DEVICE_TYPE_TUNER. - * The HDHOMERUN_TAG_DEVICE_ID value should be set to HDHOMERUN_DEVICE_ID_WILDCARD to match - * all devices, or to the 32-bit device id number to match a single device. - * - * The discovery response packet has a packet type of HDHOMERUN_TYPE_DISCOVER_RPY and has the - * same format as the discovery request packet with the two tags: HDHOMERUN_TAG_DEVICE_TYPE and - * HDHOMERUN_TAG_DEVICE_ID. In the future additional tags may also be returned - unknown tags - * should be skipped and not treated as an error. - * - * Control get/set: - * - * The payload for a control get/set request is a simple sequence of tag-length-value data - * following the same format as for discover packets. - * - * A get request packet has a packet type of HDHOMERUN_TYPE_GETSET_REQ and should contain - * the tag: HDHOMERUN_TAG_GETSET_NAME. The HDHOMERUN_TAG_GETSET_NAME value should be a sequence - * of bytes forming a null-terminated string, including the NULL. The TLV length must include - * the NULL character so the length field should be set to strlen(str) + 1. - * - * A set request packet has a packet type of HDHOMERUN_TYPE_GETSET_REQ (same as a get request) - * and should contain two tags: HDHOMERUN_TAG_GETSET_NAME and HDHOMERUN_TAG_GETSET_VALUE. - * The HDHOMERUN_TAG_GETSET_NAME value should be a sequence of bytes forming a null-terminated - * string, including the NULL. - * The HDHOMERUN_TAG_GETSET_VALUE value should be a sequence of bytes forming a null-terminated - * string, including the NULL. - * - * The get and set reply packets have the packet type HDHOMERUN_TYPE_GETSET_RPY and have the same - * format as the set request packet with the two tags: HDHOMERUN_TAG_GETSET_NAME and - * HDHOMERUN_TAG_GETSET_VALUE. A set request is also implicit get request so the updated value is - * returned. - * - * If the device encounters an error handling the get or set request then the get/set reply packet - * will contain the tag HDHOMERUN_TAG_ERROR_MESSAGE. The format of the value is a sequence of - * bytes forming a null-terminated string, including the NULL. - * - * In the future additional tags may also be returned - unknown tags should be skipped and not - * treated as an error. - * - * Security note: The application should not rely on the NULL character being present. The - * application should write a NULL character based on the TLV length to protect the application - * from a potential attack. - * - * Firmware Upgrade: - * - * A firmware upgrade packet has a packet type of HDHOMERUN_TYPE_UPGRADE_REQ and has a fixed format: - * uint32_t Position in bytes from start of file. - * uint8_t[256] Firmware data (256 bytes) - * - * The data must be uploaded in 256 byte chunks and must be uploaded in order. - * The position number is in bytes so will increment by 256 each time. - * - * When all data is uploaded it should be signaled complete by sending another packet of type - * HDHOMERUN_TYPE_UPGRADE_REQ with payload of a single uint32_t with the value 0xFFFFFFFF. - */ - -#define HDHOMERUN_DISCOVER_UDP_PORT 65001 -#define HDHOMERUN_CONTROL_TCP_PORT 65001 - -#define HDHOMERUN_MAX_PACKET_SIZE 1460 -#define HDHOMERUN_MAX_PAYLOAD_SIZE 1452 - -#define HDHOMERUN_TYPE_DISCOVER_REQ 0x0002 -#define HDHOMERUN_TYPE_DISCOVER_RPY 0x0003 -#define HDHOMERUN_TYPE_GETSET_REQ 0x0004 -#define HDHOMERUN_TYPE_GETSET_RPY 0x0005 -#define HDHOMERUN_TYPE_UPGRADE_REQ 0x0006 -#define HDHOMERUN_TYPE_UPGRADE_RPY 0x0007 - -#define HDHOMERUN_TAG_DEVICE_TYPE 0x01 -#define HDHOMERUN_TAG_DEVICE_ID 0x02 -#define HDHOMERUN_TAG_GETSET_NAME 0x03 -#define HDHOMERUN_TAG_GETSET_VALUE 0x04 -#define HDHOMERUN_TAG_GETSET_LOCKKEY 0x15 -#define HDHOMERUN_TAG_ERROR_MESSAGE 0x05 - -#define HDHOMERUN_DEVICE_TYPE_WILDCARD 0xFFFFFFFF -#define HDHOMERUN_DEVICE_TYPE_TUNER 0x00000001 -#define HDHOMERUN_DEVICE_ID_WILDCARD 0xFFFFFFFF - -#define HDHOMERUN_MIN_PEEK_LENGTH 4 - -struct hdhomerun_pkt_t { - uint8_t *pos; - uint8_t *start; - uint8_t *end; - uint8_t *limit; - uint8_t buffer[3074]; -}; - -extern LIBTYPE struct hdhomerun_pkt_t *hdhomerun_pkt_create(void); -extern LIBTYPE void hdhomerun_pkt_destroy(struct hdhomerun_pkt_t *pkt); -extern LIBTYPE void hdhomerun_pkt_reset(struct hdhomerun_pkt_t *pkt); - -extern LIBTYPE uint8_t hdhomerun_pkt_read_u8(struct hdhomerun_pkt_t *pkt); -extern LIBTYPE uint16_t hdhomerun_pkt_read_u16(struct hdhomerun_pkt_t *pkt); -extern LIBTYPE uint32_t hdhomerun_pkt_read_u32(struct hdhomerun_pkt_t *pkt); -extern LIBTYPE size_t hdhomerun_pkt_read_var_length(struct hdhomerun_pkt_t *pkt); -extern LIBTYPE uint8_t *hdhomerun_pkt_read_tlv(struct hdhomerun_pkt_t *pkt, uint8_t *ptag, size_t *plength); - -extern LIBTYPE void hdhomerun_pkt_write_u8(struct hdhomerun_pkt_t *pkt, uint8_t v); -extern LIBTYPE void hdhomerun_pkt_write_u16(struct hdhomerun_pkt_t *pkt, uint16_t v); -extern LIBTYPE void hdhomerun_pkt_write_u32(struct hdhomerun_pkt_t *pkt, uint32_t v); -extern LIBTYPE void hdhomerun_pkt_write_var_length(struct hdhomerun_pkt_t *pkt, size_t v); -extern LIBTYPE void hdhomerun_pkt_write_mem(struct hdhomerun_pkt_t *pkt, const void *mem, size_t length); - -extern LIBTYPE bool_t hdhomerun_pkt_open_frame(struct hdhomerun_pkt_t *pkt, uint16_t *ptype); -extern LIBTYPE void hdhomerun_pkt_seal_frame(struct hdhomerun_pkt_t *pkt, uint16_t frame_type); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/hdhomerun_types.h b/lib/libhdhomerun/hdhomerun_types.h deleted file mode 100644 index fdc6a25bc116b..0000000000000 --- a/lib/libhdhomerun/hdhomerun_types.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * hdhomerun_types.h - * - * Copyright © 2008 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -struct hdhomerun_device_t; - -struct hdhomerun_tuner_status_t { - char channel[32]; - char lock_str[32]; - bool_t signal_present; - bool_t lock_supported; - bool_t lock_unsupported; - unsigned int signal_strength; - unsigned int signal_to_noise_quality; - unsigned int symbol_error_quality; - uint32_t raw_bits_per_second; - uint32_t packets_per_second; -}; - -struct hdhomerun_channelscan_program_t { - char program_str[64]; - uint16_t program_number; - uint16_t virtual_major; - uint16_t virtual_minor; - uint16_t type; - char name[32]; -}; - -#define HDHOMERUN_CHANNELSCAN_MAX_PROGRAM_COUNT 64 - -struct hdhomerun_channelscan_result_t { - char channel_str[64]; - uint32_t channelmap; - uint32_t frequency; - struct hdhomerun_tuner_status_t status; - int program_count; - struct hdhomerun_channelscan_program_t programs[HDHOMERUN_CHANNELSCAN_MAX_PROGRAM_COUNT]; - uint32_t pat_crc; -}; - -struct hdhomerun_plotsample_t { - int16_t real; - int16_t imag; -}; diff --git a/lib/libhdhomerun/hdhomerun_video.c b/lib/libhdhomerun/hdhomerun_video.c deleted file mode 100644 index c382c1d7dd640..0000000000000 --- a/lib/libhdhomerun/hdhomerun_video.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * hdhomerun_video.c - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ - -#include "hdhomerun.h" - -struct hdhomerun_video_sock_t { - pthread_mutex_t lock; - uint8_t *buffer; - size_t buffer_size; - volatile size_t head; - volatile size_t tail; - size_t advance; - volatile bool_t terminate; - pthread_t thread; - int sock; - uint32_t rtp_sequence; - struct hdhomerun_debug_t *dbg; - volatile uint32_t packet_count; - volatile uint32_t transport_error_count; - volatile uint32_t network_error_count; - volatile uint32_t sequence_error_count; - volatile uint32_t overflow_error_count; - volatile uint8_t sequence[0x2000]; -}; - -static THREAD_FUNC_PREFIX hdhomerun_video_thread_execute(void *arg); - -struct hdhomerun_video_sock_t *hdhomerun_video_create(uint16_t listen_port, size_t buffer_size, struct hdhomerun_debug_t *dbg) -{ - /* Create object. */ - struct hdhomerun_video_sock_t *vs = (struct hdhomerun_video_sock_t *)calloc(1, sizeof(struct hdhomerun_video_sock_t)); - if (!vs) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: failed to allocate video object\n"); - return NULL; - } - - vs->dbg = dbg; - vs->sock = -1; - pthread_mutex_init(&vs->lock, NULL); - - /* Reset sequence tracking. */ - hdhomerun_video_flush(vs); - - /* Buffer size. */ - vs->buffer_size = (buffer_size / VIDEO_DATA_PACKET_SIZE) * VIDEO_DATA_PACKET_SIZE; - if (vs->buffer_size == 0) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: invalid buffer size (%lu bytes)\n", (unsigned long)buffer_size); - goto error; - } - vs->buffer_size += VIDEO_DATA_PACKET_SIZE; - - /* Create buffer. */ - vs->buffer = (uint8_t *)malloc(vs->buffer_size); - if (!vs->buffer) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: failed to allocate buffer (%lu bytes)\n", (unsigned long)vs->buffer_size); - goto error; - } - - /* Create socket. */ - vs->sock = (int)socket(AF_INET, SOCK_DGRAM, 0); - if (vs->sock == -1) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: failed to allocate socket\n"); - goto error; - } - - /* Expand socket buffer size. */ - int rx_size = 1024 * 1024; - setsockopt(vs->sock, SOL_SOCKET, SO_RCVBUF, (char *)&rx_size, sizeof(rx_size)); - - /* Set timeouts. */ - setsocktimeout(vs->sock, SOL_SOCKET, SO_SNDTIMEO, 1000); - setsocktimeout(vs->sock, SOL_SOCKET, SO_RCVTIMEO, 1000); - - /* Bind socket. */ - struct sockaddr_in sock_addr; - memset(&sock_addr, 0, sizeof(sock_addr)); - sock_addr.sin_family = AF_INET; - sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); - sock_addr.sin_port = htons(listen_port); - if (bind(vs->sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) != 0) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: failed to bind socket (port %u)\n", listen_port); - goto error; - } - - /* Start thread. */ - if (pthread_create(&vs->thread, NULL, &hdhomerun_video_thread_execute, vs) != 0) { - hdhomerun_debug_printf(dbg, "hdhomerun_video_create: failed to start thread\n"); - goto error; - } - - /* Success. */ - return vs; - -error: - if (vs->sock != -1) { - close(vs->sock); - } - if (vs->buffer) { - free(vs->buffer); - } - free(vs); - return NULL; -} - -void hdhomerun_video_destroy(struct hdhomerun_video_sock_t *vs) -{ - vs->terminate = TRUE; - pthread_join(vs->thread, NULL); - - close(vs->sock); - free(vs->buffer); - - free(vs); -} - -uint16_t hdhomerun_video_get_local_port(struct hdhomerun_video_sock_t *vs) -{ - struct sockaddr_in sock_addr; - socklen_t sockaddr_size = sizeof(sock_addr); - if (getsockname(vs->sock, (struct sockaddr*)&sock_addr, &sockaddr_size) != 0) { - hdhomerun_debug_printf(vs->dbg, "hdhomerun_video_get_local_port: getsockname failed (%d)\n", sock_getlasterror); - return 0; - } - - return ntohs(sock_addr.sin_port); -} - -static void hdhomerun_video_stats_ts_pkt(struct hdhomerun_video_sock_t *vs, uint8_t *ptr) -{ - uint16_t packet_identifier = ((uint16_t)(ptr[1] & 0x1F) << 8) | (uint16_t)ptr[2]; - if (packet_identifier == 0x1FFF) { - return; - } - - bool_t transport_error = ptr[1] >> 7; - if (transport_error) { - vs->transport_error_count++; - vs->sequence[packet_identifier] = 0xFF; - return; - } - - uint8_t continuity_counter = ptr[3] & 0x0F; - uint8_t previous_sequence = vs->sequence[packet_identifier]; - - if (continuity_counter == ((previous_sequence + 1) & 0x0F)) { - vs->sequence[packet_identifier] = continuity_counter; - return; - } - if (previous_sequence == 0xFF) { - vs->sequence[packet_identifier] = continuity_counter; - return; - } - if (continuity_counter == previous_sequence) { - return; - } - - vs->sequence_error_count++; - vs->sequence[packet_identifier] = continuity_counter; -} - -static void hdhomerun_video_parse_rtp(struct hdhomerun_video_sock_t *vs, struct hdhomerun_pkt_t *pkt) -{ - pkt->pos += 2; - uint32_t rtp_sequence = hdhomerun_pkt_read_u16(pkt); - pkt->pos += 8; - - if (rtp_sequence != ((vs->rtp_sequence + 1) & 0xFFFF)) { - if (vs->rtp_sequence != 0xFFFFFFFF) { - vs->network_error_count++; - - /* restart pid sequence check */ - memset((void *)vs->sequence, 0xFF, sizeof(vs->sequence)); - } - } - - vs->rtp_sequence = rtp_sequence; -} - -static THREAD_FUNC_PREFIX hdhomerun_video_thread_execute(void *arg) -{ - struct hdhomerun_video_sock_t *vs = (struct hdhomerun_video_sock_t *)arg; - struct hdhomerun_pkt_t pkt_inst; - - while (!vs->terminate) { - struct hdhomerun_pkt_t *pkt = &pkt_inst; - hdhomerun_pkt_reset(pkt); - - /* Receive. */ - int length = recv(vs->sock, (char *)pkt->end, VIDEO_RTP_DATA_PACKET_SIZE, 0); - pkt->end += length; - - if (length == VIDEO_RTP_DATA_PACKET_SIZE) { - hdhomerun_video_parse_rtp(vs, pkt); - length = (int)(pkt->end - pkt->pos); - } - - if (length != VIDEO_DATA_PACKET_SIZE) { - if (length > 0) { - /* Data received but not valid - ignore. */ - continue; - } - if (sock_getlasterror_socktimeout) { - /* Wait for more data. */ - continue; - } - vs->terminate = TRUE; - return NULL; - } - - pthread_mutex_lock(&vs->lock); - - /* Store in ring buffer. */ - size_t head = vs->head; - uint8_t *ptr = vs->buffer + head; - memcpy(ptr, pkt->pos, length); - - /* Stats. */ - vs->packet_count++; - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 0); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 1); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 2); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 3); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 4); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 5); - hdhomerun_video_stats_ts_pkt(vs, ptr + TS_PACKET_SIZE * 6); - - /* Calculate new head. */ - head += length; - if (head >= vs->buffer_size) { - head -= vs->buffer_size; - } - - /* Check for buffer overflow. */ - if (head == vs->tail) { - vs->overflow_error_count++; - pthread_mutex_unlock(&vs->lock); - continue; - } - - /* Atomic update. */ - vs->head = head; - - pthread_mutex_unlock(&vs->lock); - } - - return NULL; -} - -uint8_t *hdhomerun_video_recv(struct hdhomerun_video_sock_t *vs, size_t max_size, size_t *pactual_size) -{ - pthread_mutex_lock(&vs->lock); - - size_t head = vs->head; - size_t tail = vs->tail; - - if (vs->advance > 0) { - tail += vs->advance; - if (tail >= vs->buffer_size) { - tail -= vs->buffer_size; - } - - /* Atomic update. */ - vs->tail = tail; - } - - if (head == tail) { - vs->advance = 0; - *pactual_size = 0; - pthread_mutex_unlock(&vs->lock); - return NULL; - } - - size_t size = (max_size / VIDEO_DATA_PACKET_SIZE) * VIDEO_DATA_PACKET_SIZE; - if (size == 0) { - vs->advance = 0; - *pactual_size = 0; - pthread_mutex_unlock(&vs->lock); - return NULL; - } - - size_t avail; - if (head > tail) { - avail = head - tail; - } else { - avail = vs->buffer_size - tail; - } - if (size > avail) { - size = avail; - } - vs->advance = size; - *pactual_size = size; - uint8_t *result = vs->buffer + tail; - - pthread_mutex_unlock(&vs->lock); - return result; -} - -void hdhomerun_video_flush(struct hdhomerun_video_sock_t *vs) -{ - pthread_mutex_lock(&vs->lock); - - vs->tail = vs->head; - vs->advance = 0; - - memset((void *)vs->sequence, 0xFF, sizeof(vs->sequence)); - - vs->rtp_sequence = 0xFFFFFFFF; - - vs->packet_count = 0; - vs->transport_error_count = 0; - vs->network_error_count = 0; - vs->sequence_error_count = 0; - vs->overflow_error_count = 0; - - pthread_mutex_unlock(&vs->lock); -} - -void hdhomerun_video_debug_print_stats(struct hdhomerun_video_sock_t *vs) -{ - struct hdhomerun_video_stats_t stats; - hdhomerun_video_get_stats(vs, &stats); - - hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld\n", - stats.packet_count, stats.network_error_count, - stats.transport_error_count, stats.sequence_error_count, - stats.overflow_error_count - ); -} - -void hdhomerun_video_get_stats(struct hdhomerun_video_sock_t *vs, struct hdhomerun_video_stats_t *stats) -{ - memset(stats, 0, sizeof(struct hdhomerun_video_stats_t)); - - pthread_mutex_lock(&vs->lock); - - stats->packet_count = vs->packet_count; - stats->network_error_count = vs->network_error_count; - stats->transport_error_count = vs->transport_error_count; - stats->sequence_error_count = vs->sequence_error_count; - stats->overflow_error_count = vs->overflow_error_count; - - pthread_mutex_unlock(&vs->lock); -} diff --git a/lib/libhdhomerun/hdhomerun_video.h b/lib/libhdhomerun/hdhomerun_video.h deleted file mode 100644 index 3dba9386366a7..0000000000000 --- a/lib/libhdhomerun/hdhomerun_video.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * hdhomerun_video.h - * - * Copyright © 2006 Silicondust Engineering Ltd. . - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * As a special exception to the GNU Lesser General Public License, - * you may link, statically or dynamically, an application with a - * publicly distributed version of the Library to produce an - * executable file containing portions of the Library, and - * distribute that executable file under terms of your choice, - * without any of the additional requirements listed in clause 4 of - * the GNU Lesser General Public License. - * - * By "a publicly distributed version of the Library", we mean - * either the unmodified Library as distributed by Silicondust, or a - * modified version of the Library that is distributed under the - * conditions defined in the GNU Lesser General Public License. - */ -#ifdef __cplusplus -extern "C" { -#endif - -struct hdhomerun_video_sock_t; - -struct hdhomerun_video_stats_t { - uint32_t packet_count; - uint32_t network_error_count; - uint32_t transport_error_count; - uint32_t sequence_error_count; - uint32_t overflow_error_count; -}; - -#define TS_PACKET_SIZE 188 -#define VIDEO_DATA_PACKET_SIZE (188 * 7) -#define VIDEO_DATA_BUFFER_SIZE_1S (20000000 / 8) - -#define VIDEO_RTP_DATA_PACKET_SIZE ((188 * 7) + 12) - -/* - * Create a video/data socket. - * - * uint16_t listen_port: Port number to listen on. Set to 0 to auto-select. - * size_t buffer_size: Size of receive buffer. For 1 second of buffer use VIDEO_DATA_BUFFER_SIZE_1S. - * struct hdhomerun_debug_t *dbg: Pointer to debug logging object. May be NULL. - * - * Returns a pointer to the newly created control socket. - * - * When no longer needed, the socket should be destroyed by calling hdhomerun_control_destroy. - */ -extern LIBTYPE struct hdhomerun_video_sock_t *hdhomerun_video_create(uint16_t listen_port, size_t buffer_size, struct hdhomerun_debug_t *dbg); -extern LIBTYPE void hdhomerun_video_destroy(struct hdhomerun_video_sock_t *vs); - -/* - * Get the port the socket is listening on. - * - * Returns 16-bit port with native endianness, or 0 on error. - */ -extern LIBTYPE uint16_t hdhomerun_video_get_local_port(struct hdhomerun_video_sock_t *vs); - -/* - * Read data from buffer. - * - * size_t max_size: The maximum amount of data to be returned. - * size_t *pactual_size: The caller-supplied pactual_size value will be updated to contain the amount - * of data available to the caller. - * - * Returns a pointer to the data, or NULL if no data is available. - * The data will remain valid until another call to hdhomerun_video_recv. - * - * The amount of data returned will always be a multiple of VIDEO_DATA_PACKET_SIZE (1316). - * Attempting to read a single TS frame (188 bytes) will not return data as it is less than - * the minimum size. - * - * The buffer is implemented as a ring buffer. It is possible for this function to return a small - * amount of data when more is available due to the wrap-around case. - */ -extern LIBTYPE uint8_t *hdhomerun_video_recv(struct hdhomerun_video_sock_t *vs, size_t max_size, size_t *pactual_size); - -/* - * Flush the buffer. - */ -extern LIBTYPE void hdhomerun_video_flush(struct hdhomerun_video_sock_t *vs); - -/* - * Debug print internal stats. - */ -extern LIBTYPE void hdhomerun_video_debug_print_stats(struct hdhomerun_video_sock_t *vs); -extern LIBTYPE void hdhomerun_video_get_stats(struct hdhomerun_video_sock_t *vs, struct hdhomerun_video_stats_t *stats); - -#ifdef __cplusplus -} -#endif diff --git a/lib/libhdhomerun/lgpl.txt b/lib/libhdhomerun/lgpl.txt deleted file mode 100644 index fc8a5de7edf43..0000000000000 --- a/lib/libhdhomerun/lgpl.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/project/VS2010Express/XBMC for Windows.sln b/project/VS2010Express/XBMC for Windows.sln index 30e0fdf5e56f2..0f4a94d634257 100644 --- a/project/VS2010Express/XBMC for Windows.sln +++ b/project/VS2010Express/XBMC for Windows.sln @@ -42,8 +42,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "squish", "..\..\tools\depen EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpluff", "..\..\lib\cpluff\libcpluff\win32\cpluff.vcxproj", "{88968763-3D6B-48A8-B495-CC8C187FAC02}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libhdhomerun_dll", "..\..\lib\libhdhomerun\hdhomerun\hdhomerun.vcxproj", "{1E2FB608-3DD2-4021-A598-90008FA6DE85}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libXBMC_addon", "..\..\lib\addons\library.xbmc.addon\project\VS2010Express\libXBMC_addon.vcxproj", "{2DCEA60B-4EBC-4DB7-9FBD-297C1EFD95D7}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libKODI_guilib", "..\..\lib\addons\library.kodi.guilib\project\VS2010Express\libKODI_guilib.vcxproj", "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index 7c7a09862d415..7166ea628b45e 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -332,8 +332,6 @@ - - @@ -1117,8 +1115,6 @@ - - diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index 411d6dce18864..8f33c7e7bf638 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -1972,12 +1972,6 @@ filesystem - - filesystem - - - filesystem - filesystem @@ -4894,12 +4888,6 @@ filesystem - - filesystem - - - filesystem - filesystem diff --git a/system/playercorefactory.xml b/system/playercorefactory.xml index cff5d8be46aa7..df0e42f1f3975 100644 --- a/system/playercorefactory.xml +++ b/system/playercorefactory.xml @@ -11,7 +11,7 @@ - + diff --git a/xbmc/DllPaths_generated.h.in b/xbmc/DllPaths_generated.h.in index c92a8bd1ec9b7..262d48566997a 100644 --- a/xbmc/DllPaths_generated.h.in +++ b/xbmc/DllPaths_generated.h.in @@ -28,7 +28,6 @@ #define DLL_PATH_CPLUFF "special://xbmcbin/system/libcpluff-@ARCH@.so" #define DLL_PATH_IMAGELIB "special://xbmcbin/system/ImageLib-@ARCH@.so" #define DLL_PATH_LIBEXIF "special://xbmcbin/system/libexif-@ARCH@.so" -#define DLL_PATH_LIBHDHOMERUN "special://xbmcbin/system/hdhomerun-@ARCH@.so" #define DLL_PATH_MEDIAINFO "special://xbmcbin/system/mediainfo-@ARCH@.so" #define DLL_PATH_LIBRTMP "@RTMP_SONAME@" diff --git a/xbmc/DllPaths_generated_android.h.in b/xbmc/DllPaths_generated_android.h.in index 4369a7093c0f5..ffe9f61016a2f 100644 --- a/xbmc/DllPaths_generated_android.h.in +++ b/xbmc/DllPaths_generated_android.h.in @@ -30,7 +30,6 @@ #define DLL_PATH_CPLUFF "libcpluff-@ARCH@.so" #define DLL_PATH_IMAGELIB "libImageLib-@ARCH@.so" #define DLL_PATH_LIBEXIF "libexif-@ARCH@.so" -#define DLL_PATH_LIBHDHOMERUN "libhdhomerun-@ARCH@.so" #define DLL_PATH_MEDIAINFO "libmediainfo-@ARCH@.so" #define DLL_PATH_LIBRTMP "@RTMP_SONAME@" diff --git a/xbmc/DllPaths_win32.h b/xbmc/DllPaths_win32.h index c5026ac2a1d53..aa4d19973105d 100644 --- a/xbmc/DllPaths_win32.h +++ b/xbmc/DllPaths_win32.h @@ -25,7 +25,6 @@ #define DLL_PATH_CPLUFF "special://xbmcbin/system/cpluff.dll" #define DLL_PATH_IMAGELIB "special://xbmcbin/system/ImageLib.dll" #define DLL_PATH_LIBEXIF "special://xbmcbin/system/libexif.dll" -#define DLL_PATH_LIBHDHOMERUN "special://xbmcbin/system/hdhomerun.dll" #define DLL_PATH_LIBCURL "special://xbmcbin/system/libcurl.dll" #define DLL_PATH_LIBNFS "special://xbmcbin/system/libnfs.dll" #define DLL_PATH_LIBPLIST "special://xbmcbin/system/airplay/libplist.dll" diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index c9027d0f4c011..d9ce92538602a 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -693,7 +693,7 @@ bool CFileItem::IsVideo() const if (IsPVRRecording()) return true; - if (IsHDHomeRun() || URIUtils::IsDVD(m_strPath) || IsSlingbox()) + if (URIUtils::IsDVD(m_strPath) || IsSlingbox()) return true; std::string extension; @@ -1051,11 +1051,6 @@ bool CFileItem::IsURL() const return URIUtils::IsURL(m_strPath); } -bool CFileItem::IsHDHomeRun() const -{ - return URIUtils::IsHDHomeRun(m_strPath); -} - bool CFileItem::IsSlingbox() const { return URIUtils::IsSlingbox(m_strPath); diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h index 6824017b5ad0c..97f7ace4fe586 100644 --- a/xbmc/FileItem.h +++ b/xbmc/FileItem.h @@ -220,7 +220,6 @@ class CFileItem : bool IsParentFolder() const; bool IsFileFolder(EFileFolderType types = EFILEFOLDER_MASK_ALL) const; bool IsRemovable() const; - bool IsHDHomeRun() const; bool IsSlingbox() const; bool IsPVR() const; bool IsLiveTV() const; diff --git a/xbmc/URL.cpp b/xbmc/URL.cpp index 9eec70bb7efcd..6026f56c2046e 100644 --- a/xbmc/URL.cpp +++ b/xbmc/URL.cpp @@ -183,7 +183,6 @@ void CURL::Parse(const std::string& strURL1) || IsProtocolEqual(strProtocol2, "https") || IsProtocolEqual(strProtocol2, "plugin") || IsProtocolEqual(strProtocol2, "addons") - || IsProtocolEqual(strProtocol2, "hdhomerun") || IsProtocolEqual(strProtocol2, "rtsp")) sep = "?;#|"; else if(IsProtocolEqual(strProtocol2, "ftp") diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 5a22917bfe60f..bc34de46a6fe6 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -167,10 +167,6 @@ std::string CUtil::GetTitleFromPath(const CURL& url, bool bIsFolder /* = false * strFilename = url.GetHostName(); } } - // HDHomerun Devices - else if (url.IsProtocol("hdhomerun") && strFilename.empty()) - strFilename = "HDHomerun Devices"; - // Slingbox Devices else if (url.IsProtocol("sling")) strFilename = "Slingbox"; @@ -432,10 +428,6 @@ bool CUtil::IsLiveTV(const std::string& strFile) if (StringUtils::StartsWithNoCase(strFile, "pvr://channels")) return true; - if(URIUtils::IsHDHomeRun(strFile) - || StringUtils::StartsWithNoCase(strFile, "sap:")) - return true; - return false; } @@ -1716,7 +1708,6 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector. - * - */ - -#include "DynamicDll.h" -#include "lib/libhdhomerun/hdhomerun.h" - -class DllHdHomeRunInterface -{ -public: - virtual ~DllHdHomeRunInterface() {} - virtual int discover_find_devices_custom(uint32_t target_ip, uint32_t device_type, uint32_t device_id, struct hdhomerun_discover_device_t result_list[], int max_count)=0; - virtual struct hdhomerun_device_t* device_create_from_str(const char *device_str, struct hdhomerun_debug_t *dbg)=0; - virtual void device_destroy(struct hdhomerun_device_t *hd)=0; - virtual int device_stream_start(struct hdhomerun_device_t *hd)=0; - virtual uint8_t* device_stream_recv(struct hdhomerun_device_t *hd, size_t max_size, size_t* pactual_size)=0; - virtual void device_stream_stop(struct hdhomerun_device_t *hd)=0; - virtual int device_set_tuner_channel(struct hdhomerun_device_t *hd, const char *channel)=0; - virtual int device_set_tuner_program(struct hdhomerun_device_t *hd, const char *program)=0; - virtual int device_set_tuner_from_str(struct hdhomerun_device_t *hd, const char *tuner_str)=0; - virtual void device_set_tuner(struct hdhomerun_device_t *hd, unsigned int tuner)=0; - virtual int device_get_tuner_status(struct hdhomerun_device_t *hd, char **pstatus_str, struct hdhomerun_tuner_status_t *status)=0; -}; - -class DllHdHomeRun : public DllDynamic, public DllHdHomeRunInterface -{ - DECLARE_DLL_WRAPPER(DllHdHomeRun, DLL_PATH_LIBHDHOMERUN) - DEFINE_METHOD5(int, discover_find_devices_custom, (uint32_t p1, uint32_t p2, uint32_t p3, struct hdhomerun_discover_device_t p4[], int p5)) - DEFINE_METHOD2(struct hdhomerun_device_t*, device_create_from_str, (const char* p1, struct hdhomerun_debug_t *p2)) - DEFINE_METHOD1(void, device_destroy, (struct hdhomerun_device_t* p1)) - DEFINE_METHOD1(int, device_stream_start, (struct hdhomerun_device_t* p1)) - DEFINE_METHOD3(uint8_t*, device_stream_recv, (struct hdhomerun_device_t* p1, size_t p2, size_t* p3)) - DEFINE_METHOD1(void, device_stream_stop, (struct hdhomerun_device_t* p1)) - DEFINE_METHOD2(int, device_set_tuner_channel, (struct hdhomerun_device_t *p1, const char *p2)) - DEFINE_METHOD2(int, device_set_tuner_program, (struct hdhomerun_device_t *p1, const char *p2)) - DEFINE_METHOD2(int, device_set_tuner_from_str, (struct hdhomerun_device_t *p1, const char *p2)) - DEFINE_METHOD2(void, device_set_tuner, (struct hdhomerun_device_t *p1, unsigned int p2)) - DEFINE_METHOD3(int, device_get_tuner_status, (struct hdhomerun_device_t *p1, char **p2, struct hdhomerun_tuner_status_t *p3)); - BEGIN_METHOD_RESOLVE() - RESOLVE_METHOD_RENAME(hdhomerun_discover_find_devices_custom, discover_find_devices_custom) - RESOLVE_METHOD_RENAME(hdhomerun_device_create_from_str, device_create_from_str) - RESOLVE_METHOD_RENAME(hdhomerun_device_destroy, device_destroy) - RESOLVE_METHOD_RENAME(hdhomerun_device_stream_start, device_stream_start) - RESOLVE_METHOD_RENAME(hdhomerun_device_stream_recv, device_stream_recv) - RESOLVE_METHOD_RENAME(hdhomerun_device_stream_stop, device_stream_stop) - RESOLVE_METHOD_RENAME(hdhomerun_device_set_tuner_channel, device_set_tuner_channel) - RESOLVE_METHOD_RENAME(hdhomerun_device_set_tuner_program, device_set_tuner_program) - RESOLVE_METHOD_RENAME(hdhomerun_device_set_tuner_from_str, device_set_tuner_from_str) - RESOLVE_METHOD_RENAME(hdhomerun_device_set_tuner, device_set_tuner) - RESOLVE_METHOD_RENAME(hdhomerun_device_get_tuner_status, device_get_tuner_status) - END_METHOD_RESOLVE() -}; - diff --git a/xbmc/filesystem/FileFactory.cpp b/xbmc/filesystem/FileFactory.cpp index c34bd13d650e5..644eb90c7fed9 100644 --- a/xbmc/filesystem/FileFactory.cpp +++ b/xbmc/filesystem/FileFactory.cpp @@ -80,7 +80,6 @@ #include "SpecialProtocolFile.h" #include "MultiPathFile.h" #include "UDFFile.h" -#include "HDHomeRunFile.h" #include "SlingboxFile.h" #include "ImageFile.h" #include "ResourceFile.h" @@ -156,7 +155,6 @@ IFile* CFileFactory::CreateLoader(const CURL& url) else if (url.IsProtocol("sftp") || url.IsProtocol("ssh")) return new CSFTPFile(); #endif else if (url.IsProtocol("shout")) return new CShoutcastFile(); - else if (url.IsProtocol("hdhomerun")) return new CHomeRunFile(); else if (url.IsProtocol("sling")) return new CSlingboxFile(); #ifdef HAS_FILESYSTEM_SMB #ifdef TARGET_WINDOWS diff --git a/xbmc/filesystem/HDHomeRunDirectory.cpp b/xbmc/filesystem/HDHomeRunDirectory.cpp deleted file mode 100644 index b52a44f58f5b4..0000000000000 --- a/xbmc/filesystem/HDHomeRunDirectory.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2011-2013 Team XBMC - * http://xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "HDHomeRunDirectory.h" -#include "URL.h" -#include "FileItem.h" -#include "utils/URIUtils.h" -#include "utils/StringUtils.h" -#include "DllHDHomeRun.h" - -using namespace XFILE; -using namespace std; - -// ------------------------------------------- -// ---------------- Directory ---------------- -// ------------------------------------------- - -CHomeRunDirectory::CHomeRunDirectory() -{ - m_pdll = new DllHdHomeRun; - m_pdll->Load(); -} - -CHomeRunDirectory::~CHomeRunDirectory() -{ - m_pdll->Unload(); - delete m_pdll; -} - -bool CHomeRunDirectory::GetDirectory(const CURL& url, CFileItemList &items) -{ - if(!m_pdll->IsLoaded()) - return false; - - if(url.GetHostName().empty()) - { - // no hostname, list all available devices - int target_ip = 0; - struct hdhomerun_discover_device_t result_list[64]; - int count = m_pdll->discover_find_devices_custom(target_ip, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, result_list, 64); - if (count < 0) - return false; - - for(int i=0;i> 24) & 0xFF, (unsigned int)(ip_addr >> 16) & 0xFF, - (unsigned int)(ip_addr >> 8) & 0xFF, (unsigned int)(ip_addr >> 0) & 0xFF); - - item.reset(new CFileItem("hdhomerun://" + device + "/tuner0/", true)); - item->SetLabel(device + "-0 On " + ip); - item->SetLabelPreformated(true); - items.Add(item); - - item.reset(new CFileItem("hdhomerun://" + device + "/tuner1/", true)); - item->SetLabel(device + "-1 On " + ip); - item->SetLabelPreformated(true); - items.Add(item); - } - return true; - } - else - { - hdhomerun_device_t* device = m_pdll->device_create_from_str(url.GetHostName().c_str(), NULL); - if(!device) - return false; - - m_pdll->device_set_tuner_from_str(device, url.GetFileName().c_str()); - - hdhomerun_tuner_status_t status; - if(!m_pdll->device_get_tuner_status(device, NULL, &status)) - { - m_pdll->device_destroy(device); - return true; - } - - std::string label; - if(status.signal_present) - label = StringUtils::Format("Current Stream: N/A"); - else - label = StringUtils::Format("Current Stream: Channel %s, SNR %d", status.channel, status.signal_to_noise_quality); - - std::string path = "hdhomerun://" + url.GetHostName() + "/" + url.GetFileName(); - URIUtils::RemoveSlashAtEnd(path); - CFileItemPtr item(new CFileItem(path, false)); - item->SetLabel(label); - item->SetLabelPreformated(true); - items.Add(item); - - m_pdll->device_destroy(device); - return true; - } - - return false; -} diff --git a/xbmc/filesystem/HDHomeRunDirectory.h b/xbmc/filesystem/HDHomeRunDirectory.h deleted file mode 100644 index 55a80bbbe9f6c..0000000000000 --- a/xbmc/filesystem/HDHomeRunDirectory.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -/* - * Copyright (C) 2011-2013 Team XBMC - * http://xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - - #include "IDirectory.h" - -class DllHdHomeRun; - -namespace XFILE -{ - class CHomeRunDirectory : public IDirectory - { - public: - CHomeRunDirectory(void); - virtual ~CHomeRunDirectory(void); - virtual bool AllowAll() const { return true; } - virtual bool GetDirectory(const CURL& url, CFileItemList &items); - private: - DllHdHomeRun* m_pdll; - }; -} diff --git a/xbmc/filesystem/HDHomeRunFile.cpp b/xbmc/filesystem/HDHomeRunFile.cpp deleted file mode 100644 index 746aaa6a78d30..0000000000000 --- a/xbmc/filesystem/HDHomeRunFile.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2011-2013 Team XBMC - * http://xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "threads/SystemClock.h" -#include "system.h" -#include "URL.h" -#include "FileItem.h" -#include "HDHomeRunFile.h" -#include "utils/log.h" -#include "utils/StringUtils.h" -#include "utils/URIUtils.h" -#include "DllHDHomeRun.h" - -using namespace XFILE; -using namespace std; - -// ------------------------------------------- -// ------------------ File ------------------- -// ------------------------------------------- -CHomeRunFile::CHomeRunFile() -{ - m_device = NULL; - m_pdll = new DllHdHomeRun; - m_pdll->Load(); -} - -CHomeRunFile::~CHomeRunFile() -{ - Close(); - delete m_pdll; -} - -bool CHomeRunFile::Exists(const CURL& url) -{ - std::string path(url.GetFileName()); - - /* - * HDHomeRun URLs are of the form hdhomerun://1014F6D1/tuner0?channel=qam:108&program=10 - * The filename starts with "tuner" and has no extension. This check will cover off requests - * for *.tbn, *.jpg, *.jpeg, *.edl etc. that do not exist. - */ - return StringUtils::StartsWith(path, "tuner") && - !URIUtils::HasExtension(path); -} - -int64_t CHomeRunFile::Seek(int64_t iFilePosition, int iWhence) -{ - return -1; -} - -int CHomeRunFile::Stat(const CURL& url, struct __stat64* buffer) -{ - memset(buffer, 0, sizeof(struct __stat64)); - return 0; -} - -int64_t CHomeRunFile::GetPosition() -{ - return 0; -} - -int64_t CHomeRunFile::GetLength() -{ - return 0; -} - -bool CHomeRunFile::Open(const CURL &url) -{ - if(!m_pdll->IsLoaded()) - return false; - - m_device = m_pdll->device_create_from_str(url.GetHostName().c_str(), NULL); - if(!m_device) - return false; - - m_pdll->device_set_tuner_from_str(m_device, url.GetFileName().c_str()); - - if(url.HasOption("channel")) - m_pdll->device_set_tuner_channel(m_device, url.GetOption("channel").c_str()); - - if(url.HasOption("program")) - m_pdll->device_set_tuner_program(m_device, url.GetOption("program").c_str()); - - // start streaming from selected device and tuner - if( m_pdll->device_stream_start(m_device) <= 0 ) - return false; - - return true; -} - -ssize_t CHomeRunFile::Read(void* lpBuf, size_t uiBufSize) -{ - if (uiBufSize > SSIZE_MAX) - uiBufSize = SSIZE_MAX; - - size_t datasize; - - if(uiBufSize < VIDEO_DATA_PACKET_SIZE) - CLog::Log(LOGWARNING, "CHomeRunFile::Read - buffer size too small, will most likely fail"); - - // for now, let it it time out after 5 seconds, - // neither of the players can be forced to - // continue even if read return 0 as can happen - // on live streams. - XbmcThreads::EndTime timestamp(5000); - while(1) - { - datasize = (size_t) uiBufSize; - uint8_t* ptr = m_pdll->device_stream_recv(m_device, datasize, &datasize); - if(ptr) - { - memcpy(lpBuf, ptr, datasize); - return datasize; - } - - if(timestamp.IsTimePast()) - return 0; - - Sleep(64); - } - return datasize; -} - -void CHomeRunFile::Close() -{ - if(m_device) - { - m_pdll->device_stream_stop(m_device); - m_pdll->device_destroy(m_device); - m_device = NULL; - } -} - -int CHomeRunFile::GetChunkSize() -{ - return VIDEO_DATA_PACKET_SIZE; -} diff --git a/xbmc/filesystem/HDHomeRunFile.h b/xbmc/filesystem/HDHomeRunFile.h deleted file mode 100644 index 0c1be66891489..0000000000000 --- a/xbmc/filesystem/HDHomeRunFile.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -/* - * Copyright (C) 2011-2013 Team XBMC - * http://xbmc.org - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with XBMC; see the file COPYING. If not, see - * . - * - */ - -#include "IFile.h" - -struct hdhomerun_device_t; -class DllHdHomeRun; - -namespace XFILE -{ - class CHomeRunFile : public IFile - { - public: - CHomeRunFile(); - ~CHomeRunFile(); - - virtual bool Exists(const CURL& url); - virtual int64_t Seek(int64_t iFilePosition, int iWhence); - virtual int Stat(const CURL& url, struct __stat64* buffer); - virtual int64_t GetPosition(); - virtual int64_t GetLength(); - - virtual bool Open(const CURL& url); - virtual void Close(); - virtual ssize_t Read(void* lpBuf, size_t uiBufSize); - virtual int GetChunkSize(); - private: - struct hdhomerun_device_t* m_device; - DllHdHomeRun* m_pdll; - }; -} diff --git a/xbmc/filesystem/Makefile.in b/xbmc/filesystem/Makefile.in index 541b53b5be661..4e689aa693c48 100644 --- a/xbmc/filesystem/Makefile.in +++ b/xbmc/filesystem/Makefile.in @@ -22,8 +22,6 @@ SRCS += FileFactory.cpp SRCS += FileReaderFile.cpp SRCS += FTPDirectory.cpp SRCS += FTPParse.cpp -SRCS += HDHomeRunDirectory.cpp -SRCS += HDHomeRunFile.cpp SRCS += HTTPDirectory.cpp SRCS += HTTPFile.cpp SRCS += IDirectory.cpp diff --git a/xbmc/utils/URIUtils.cpp b/xbmc/utils/URIUtils.cpp index c6d8511a1081a..15c1a9aeb243a 100644 --- a/xbmc/utils/URIUtils.cpp +++ b/xbmc/utils/URIUtils.cpp @@ -954,11 +954,6 @@ bool URIUtils::IsUPnP(const std::string& strFile) return IsProtocol(strFile, "upnp"); } -bool URIUtils::IsHDHomeRun(const std::string& strFile) -{ - return IsProtocol(strFile, "hdhomerun"); -} - bool URIUtils::IsSlingbox(const std::string& strFile) { return IsProtocol(strFile, "sling"); @@ -969,8 +964,7 @@ bool URIUtils::IsLiveTV(const std::string& strFile) std::string strFileWithoutSlash(strFile); RemoveSlashAtEnd(strFileWithoutSlash); - if (IsHDHomeRun(strFile) - || IsSlingbox(strFile) + if (IsSlingbox(strFile) || IsProtocol(strFile, "sap") ||(StringUtils::EndsWithNoCase(strFileWithoutSlash, ".pvr") && !PathStarts(strFileWithoutSlash, "pvr://recordings"))) return true; diff --git a/xbmc/utils/URIUtils.h b/xbmc/utils/URIUtils.h index 90e7b442ab2cc..78a3d70ff423a 100644 --- a/xbmc/utils/URIUtils.h +++ b/xbmc/utils/URIUtils.h @@ -130,7 +130,6 @@ class URIUtils static bool IsUDP(const std::string& strFile); static bool IsTCP(const std::string& strFile); static bool IsHD(const std::string& strFileName); - static bool IsHDHomeRun(const std::string& strFile); static bool IsSlingbox(const std::string& strFile); static bool IsInArchive(const std::string& strFile); static bool IsInRAR(const std::string& strFile); diff --git a/xbmc/utils/test/TestURIUtils.cpp b/xbmc/utils/test/TestURIUtils.cpp index 6cda9c96141b1..9b3db8704bae0 100644 --- a/xbmc/utils/test/TestURIUtils.cpp +++ b/xbmc/utils/test/TestURIUtils.cpp @@ -281,11 +281,6 @@ TEST_F(TestURIUtils, IsHD) EXPECT_TRUE(URIUtils::IsHD("rar://path/to/file")); } -TEST_F(TestURIUtils, IsHDHomeRun) -{ - EXPECT_TRUE(URIUtils::IsHDHomeRun("hdhomerun://path/to/file")); -} - TEST_F(TestURIUtils, IsSlingbox) { EXPECT_TRUE(URIUtils::IsSlingbox("sling://path/to/file")); @@ -322,7 +317,6 @@ TEST_F(TestURIUtils, IsISO9660) TEST_F(TestURIUtils, IsLiveTV) { - EXPECT_TRUE(URIUtils::IsLiveTV("hdhomerun://path/to/file")); EXPECT_TRUE(URIUtils::IsLiveTV("sling://path/to/file")); EXPECT_TRUE(URIUtils::IsLiveTV("sap://path/to/file")); }