PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/atmo.cpp

https://bitbucket.org/RickDB/atmowin-atmoduino-mod
C++ | 2840 lines | 1814 code | 432 blank | 594 comment | 224 complexity | 1757f4a6a39298d6c7b8beb94bdf23d9 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*****************************************************************************
  2. * atmo.cpp : "Atmo Light" video filter
  3. *****************************************************************************
  4. * Copyright (C) 2000-2006 the VideoLAN team
  5. * $Id: 381928c8d0487de635cc45bbf7ca49acf30f3a72 $
  6. *
  7. * Authors: André Weber (WeberAndre@gmx.de)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22. *****************************************************************************/
  23. #ifdef HAVE_CONFIG_H
  24. # include "config.h"
  25. #endif
  26. /*****************************************************************************
  27. * Preamble
  28. *****************************************************************************/
  29. #define __STDC_FORMAT_MACROS 1
  30. #include <stdlib.h> /* malloc(), free() */
  31. #include <string.h>
  32. #include <math.h> /* sin(), cos() */
  33. #include <assert.h>
  34. // #define __ATMO_DEBUG__
  35. // [:Zs]+$
  36. #include <vlc_common.h>
  37. #include <vlc_plugin.h>
  38. #include <vlc_vout.h>
  39. #include <vlc_playlist.h>
  40. #include <vlc_filter.h>
  41. #include <vlc_atomic.h>
  42. #include "filter_picture.h"
  43. #include "AtmoDefs.h"
  44. #include "AtmoDynData.h"
  45. #include "AtmoLiveView.h"
  46. #include "AtmoTools.h"
  47. #include "AtmoExternalCaptureInput.h"
  48. #include "AtmoConfig.h"
  49. #include "AtmoConnection.h"
  50. #include "AtmoClassicConnection.h"
  51. /*****************************************************************************
  52. * Local prototypes
  53. *****************************************************************************/
  54. /* directly to vlc related functions required that the module is accepted */
  55. static int CreateFilter ( vlc_object_t * );
  56. static void DestroyFilter ( vlc_object_t * );
  57. static picture_t * Filter( filter_t *, picture_t *);
  58. /* callback for global variable state pause / continue / stop events */
  59. static void AddStateVariableCallback( filter_t *);
  60. static void DelStateVariableCallback( filter_t *);
  61. static int StateCallback(vlc_object_t *, char const *,
  62. vlc_value_t, vlc_value_t, void *);
  63. /* callback for atmo settings variables whose change
  64. should be immediately realized and applied to output
  65. */
  66. static void DelAtmoSettingsVariablesCallbacks(filter_t *);
  67. static void AddAtmoSettingsVariablesCallbacks(filter_t *);
  68. static int AtmoSettingsCallback(vlc_object_t *, char const *,
  69. vlc_value_t, vlc_value_t, void *);
  70. #if defined(__ATMO_DEBUG__)
  71. static void atmo_parse_crop(char *psz_cropconfig,
  72. video_format_t fmt_in,
  73. video_format_t fmt_render,
  74. int &i_visible_width,
  75. int &i_visible_height,
  76. int &i_x_offset,
  77. int &i_y_offset );
  78. #endif
  79. /* function to shutdown the fade thread which is started on pause*/
  80. static void CheckAndStopFadeThread(filter_t *);
  81. /* extracts a small RGB (BGR) Image from an YUV image */
  82. static void ExtractMiniImage_YUV(filter_sys_t *, picture_t *, uint8_t *);
  83. #if defined(__ATMO_DEBUG__)
  84. void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename);
  85. #endif
  86. /*****************************************************************************
  87. * External Prototypes for the AtmoCtrlLib.DLL
  88. *****************************************************************************/
  89. /*
  90. * if effectmode = emLivePicture then the source could be GDI (Screencapture)
  91. * or External - this means another application delivers Pixeldata to AtmoWin
  92. * Clientsoftware through AtmoCtrlLib.DLL and the COM Api
  93. */
  94. #define lvsGDI 0
  95. #define lvsExternal 1
  96. #define CLASSIC_ATMO_NUM_ZONES 5
  97. /*
  98. strings for settings menus and hints
  99. */
  100. #define MODULE_DESCRIPTION N_ ( \
  101. "This module allows to control an so called AtmoLight device "\
  102. "connected to your computer.\n"\
  103. "AtmoLight is the homegrown version of what Philips calls AmbiLight.\n"\
  104. "If you need further information feel free to visit us at\n\n"\
  105. "http://www.vdr-wiki.de/wiki/index.php/Atmo-plugin\n"\
  106. "http://www.vdr-wiki.de/wiki/index.php/AtmoWin\n\n"\
  107. "You can find there detailed descriptions on how to build it for yourself "\
  108. "and where to get the required parts.\n" \
  109. "You can also have a look at pictures and some movies showing such a device " \
  110. "in live action.")
  111. #define DRIVER_TEXT N_("Device type")
  112. #define DRIVER_LONGTEXT N_("Choose your preferred hardware from " \
  113. "the list, or choose AtmoWin Software " \
  114. "to delegate processing to the external " \
  115. "process - with more options")
  116. static const int pi_device_type_values[] = {
  117. #if defined( WIN32 )
  118. 0, /* use AtmoWinA.exe userspace driver */
  119. #endif
  120. 1, /* AtmoLight classic */
  121. 2, /* Quattro AtmoLight */
  122. 3, /* DMX Device */
  123. 4, /* MoMoLight device */
  124. 5 /* fnordlicht */
  125. };
  126. static const char *const ppsz_device_type_descriptions[] = {
  127. #if defined( WIN32 )
  128. N_("AtmoWin Software"),
  129. #endif
  130. N_("Classic AtmoLight"),
  131. N_("Quattro AtmoLight"),
  132. N_("DMX"),
  133. N_("MoMoLight"),
  134. N_("fnordlicht")
  135. };
  136. #define DMX_CHANNELS_TEXT N_("Count of AtmoLight channels")
  137. #define DMX_CHANNELS_LONGTEXT N_("How many AtmoLight channels, should be " \
  138. "emulated with that DMX device")
  139. #define DMX_CHBASE_TEXT N_("DMX address for each channel")
  140. #define DMX_CHBASE_LONGTEXT N_("Define here the DMX base address for each " \
  141. "channel use , or ; to separate the values")
  142. #define MOMO_CHANNELS_TEXT N_("Count of channels")
  143. #define MOMO_CHANNELS_LONGTEXT N_("Depending on your MoMoLight hardware " \
  144. "choose 3 or 4 channels")
  145. #define FNORDLICHT_AMOUNT_TEXT N_("Count of fnordlicht's")
  146. #define FNORDLICHT_AMOUNT_LONGTEXT N_("Depending on the amount your " \
  147. "fnordlicht hardware " \
  148. "choose 1 to 254 channels")
  149. #if defined( WIN32 )
  150. # define DEFAULT_DEVICE 0
  151. #else
  152. # define DEFAULT_DEVICE 1
  153. #endif
  154. #if defined( __ATMO_DEBUG__ )
  155. # define SAVEFRAMES_TEXT N_("Save Debug Frames")
  156. # define SAVEFRAMES_LONGTEXT N_("Write every 128th miniframe to a folder.")
  157. # define FRAMEPATH_TEXT N_("Debug Frame Folder")
  158. # define FRAMEPATH_LONGTEXT N_("The path where the debugframes " \
  159. "should be saved")
  160. #endif
  161. #define WIDTH_TEXT N_("Extracted Image Width")
  162. #define WIDTH_LONGTEXT N_("The width of the mini image for " \
  163. "further processing (64 is default)")
  164. #define HEIGHT_TEXT N_("Extracted Image Height")
  165. #define HEIGHT_LONGTEXT N_("The height of the mini image for " \
  166. "further processing (48 is default)")
  167. #define SHOW_DOTS_TEXT N_("Mark analyzed pixels")
  168. #define SHOW_DOTS_LONGTEXT N_("makes the sample grid visible on screen as "\
  169. "white pixels")
  170. #define PCOLOR_TEXT N_("Color when paused")
  171. #define PCOLOR_LONGTEXT N_("Set the color to show if the user " \
  172. "pauses the video. (Have light to get " \
  173. "another beer?)")
  174. #define PCOLOR_RED_TEXT N_("Pause-Red")
  175. #define PCOLOR_RED_LONGTEXT N_("Red component of the pause color")
  176. #define PCOLOR_GREEN_TEXT N_("Pause-Green")
  177. #define PCOLOR_GREEN_LONGTEXT N_("Green component of the pause color")
  178. #define PCOLOR_BLUE_TEXT N_("Pause-Blue")
  179. #define PCOLOR_BLUE_LONGTEXT N_("Blue component of the pause color")
  180. #define FADESTEPS_TEXT N_("Pause-Fadesteps")
  181. #define FADESTEPS_LONGTEXT N_("Number of steps to change current color " \
  182. "to pause color (each step takes 40ms)")
  183. #define ECOLOR_RED_TEXT N_("End-Red")
  184. #define ECOLOR_RED_LONGTEXT N_("Red component of the shutdown color")
  185. #define ECOLOR_GREEN_TEXT N_("End-Green")
  186. #define ECOLOR_GREEN_LONGTEXT N_("Green component of the shutdown color")
  187. #define ECOLOR_BLUE_TEXT N_("End-Blue")
  188. #define ECOLOR_BLUE_LONGTEXT N_("Blue component of the shutdown color")
  189. #define EFADESTEPS_TEXT N_("End-Fadesteps")
  190. #define EFADESTEPS_LONGTEXT N_("Number of steps to change current color to " \
  191. "end color for dimming up the light in cinema " \
  192. "style... (each step takes 40ms)")
  193. #define ZONE_TOP_TEXT N_("Number of zones on top")
  194. #define ZONE_TOP_LONGTEXT N_("Number of zones on the top of the screen")
  195. #define ZONE_BOTTOM_TEXT N_("Number of zones on bottom")
  196. #define ZONE_BOTTOM_LONGTEXT N_("Number of zones on the bottom of the screen")
  197. #define ZONE_LR_TEXT N_("Zones on left / right side")
  198. #define ZONE_LR_LONGTEXT N_("left and right side having allways the " \
  199. "same number of zones")
  200. #define ZONE_SUMMARY_TEXT N_("Calculate a average zone")
  201. #define ZONE_SUMMARY_LONGTEXT N_("it contains the average of all pixels " \
  202. "in the sample image (only useful for " \
  203. "single channel AtmoLight)")
  204. #define USEWHITEADJ_TEXT N_("Use Software White adjust")
  205. #define USEWHITEADJ_LONGTEXT N_("Should the buildin driver do a white " \
  206. "adjust or your LED stripes? recommend.")
  207. #define WHITE_RED_TEXT N_("White Red")
  208. #define WHITE_RED_LONGTEXT N_("Red value of a pure white on your "\
  209. "LED stripes.")
  210. #define WHITE_GREEN_TEXT N_("White Green")
  211. #define WHITE_GREEN_LONGTEXT N_("Green value of a pure white on your "\
  212. "LED stripes.")
  213. #define WHITE_BLUE_TEXT N_("White Blue")
  214. #define WHITE_BLUE_LONGTEXT N_("Blue value of a pure white on your "\
  215. "LED stripes.")
  216. #define SERIALDEV_TEXT N_("Serial Port/Device")
  217. #define SERIALDEV_LONGTEXT N_("Name of the serial port where the AtmoLight "\
  218. "controller is attached to.\n" \
  219. "On Windows usually something like COM1 or " \
  220. "COM2. On Linux /dev/ttyS01 f.e.")
  221. #define EDGE_TEXT N_("Edge Weightning")
  222. #define EDGE_LONGTEXT N_("Increasing this value will result in color "\
  223. "more depending on the border of the frame.")
  224. #define BRIGHTNESS_TEXT N_("Brightness")
  225. #define BRIGHTNESS_LONGTEXT N_("Overall brightness of your LED stripes")
  226. #define DARKNESS_TEXT N_("Darkness Limit")
  227. #define DARKNESS_LONGTEXT N_("Pixels with a saturation lower than this will "\
  228. "be ignored. Should be greater than one for "\
  229. "letterboxed videos.")
  230. #define HUEWINSIZE_TEXT N_("Hue windowing")
  231. #define HUEWINSIZE_LONGTEXT N_("Used for statistics.")
  232. #define SATWINSIZE_TEXT N_("Sat windowing")
  233. #define SATWINSIZE_LONGTEXT N_("Used for statistics.")
  234. #define MEANLENGTH_TEXT N_("Filter length (ms)")
  235. #define MEANLENGTH_LONGTEXT N_("Time it takes until a color is completely "\
  236. "changed. This prevents flickering.")
  237. #define MEANTHRESHOLD_TEXT N_("Filter threshold")
  238. #define MEANTHRESHOLD_LONGTEXT N_("How much a color has to be changed for an "\
  239. "immediate color change.")
  240. #define MEANPERCENTNEW_TEXT N_("Filter Smoothness (in %)")
  241. #define MEANPERCENTNEW_LONGTEXT N_("Filter Smoothness")
  242. #define FILTERMODE_TEXT N_("Output Color filter mode")
  243. #define FILTERMODE_LONGTEXT N_("defines the how the output color should " \
  244. "be calculated based on previous color")
  245. static const int pi_filtermode_values[] = {
  246. (int)afmNoFilter,
  247. (int)afmCombined,
  248. (int)afmPercent
  249. };
  250. static const char *const ppsz_filtermode_descriptions[] = {
  251. N_("No Filtering"),
  252. N_("Combined"),
  253. N_("Percent")
  254. };
  255. #define FRAMEDELAY_TEXT N_("Frame delay (ms)")
  256. #define FRAMEDELAY_LONGTEXT N_("Helps to get the video output and the light "\
  257. "effects in sync. Values around 20ms should " \
  258. "do the trick.")
  259. #define CHANNEL_0_ASSIGN_TEXT N_("Channel 0: summary")
  260. #define CHANNEL_1_ASSIGN_TEXT N_("Channel 1: left")
  261. #define CHANNEL_2_ASSIGN_TEXT N_("Channel 2: right")
  262. #define CHANNEL_3_ASSIGN_TEXT N_("Channel 3: top")
  263. #define CHANNEL_4_ASSIGN_TEXT N_("Channel 4: bottom")
  264. #define CHANNELASSIGN_LONGTEXT N_("Maps the hardware channel X to logical "\
  265. "zone Y to fix wrong wiring :-)")
  266. static const int pi_zone_assignment_values[] = {
  267. -1,
  268. 4,
  269. 3,
  270. 1,
  271. 0,
  272. 2
  273. };
  274. static const char *const ppsz_zone_assignment_descriptions[] = {
  275. N_("disabled"),
  276. N_("Zone 4:summary"),
  277. N_("Zone 3:left"),
  278. N_("Zone 1:right"),
  279. N_("Zone 0:top"),
  280. N_("Zone 2:bottom")
  281. };
  282. #define CHANNELS_ASSIGN_TEXT N_("Channel / Zone Assignment")
  283. #define CHANNELS_ASSIGN_LONGTEXT N_("for devices with more than five " \
  284. "channels / zones write down here for each channel " \
  285. "the zone number to show and separate the values with " \
  286. ", or ; and use -1 to not use some channels. For the " \
  287. "classic AtmoLight the sequence 4,3,1,0,2 would set the " \
  288. "default channel/zone mapping. " \
  289. "Having only two zones on top, and one zone on left and " \
  290. "right and no summary zone the mapping for classic " \
  291. "AtmoLight would be -1,3,2,1,0")
  292. #define ZONE_0_GRADIENT_TEXT N_("Zone 0: Top gradient")
  293. #define ZONE_1_GRADIENT_TEXT N_("Zone 1: Right gradient")
  294. #define ZONE_2_GRADIENT_TEXT N_("Zone 2: Bottom gradient")
  295. #define ZONE_3_GRADIENT_TEXT N_("Zone 3: Left gradient")
  296. #define ZONE_4_GRADIENT_TEXT N_("Zone 4: Summary gradient")
  297. #define ZONE_X_GRADIENT_LONG_TEXT N_("Defines a small bitmap with 64x48 "\
  298. "pixels, containing a grayscale gradient")
  299. #define GRADIENT_PATH_TEXT N_("Gradient bitmap searchpath")
  300. #define GRADIENT_PATH_LONGTEXT N_("Now preferred option to assign gradient "\
  301. "bitmaps, put them as zone_0.bmp, zone_1.bmp etc. into one folder and "\
  302. "set the foldername here")
  303. #if defined( WIN32 )
  304. # define ATMOWINEXE_TEXT N_("Filename of AtmoWin*.exe")
  305. # define ATMOWINEXE_LONGTEXT N_("if you want the AtmoLight control "\
  306. "software to be launched by VLC, enter the "\
  307. "complete path of AtmoWinA.exe here.")
  308. #endif
  309. #define CFG_PREFIX "atmo-"
  310. /*****************************************************************************
  311. * Module descriptor
  312. *****************************************************************************/
  313. vlc_module_begin ()
  314. set_description( N_("AtmoLight Filter") )
  315. set_help( MODULE_DESCRIPTION )
  316. set_shortname( N_( "AtmoLight" ))
  317. set_category( CAT_VIDEO )
  318. set_subcategory( SUBCAT_VIDEO_VFILTER )
  319. set_capability( "video filter2", 0 )
  320. set_section( N_("Choose Devicetype and Connection" ), 0 )
  321. add_integer( CFG_PREFIX "device", DEFAULT_DEVICE,
  322. DRIVER_TEXT, DRIVER_LONGTEXT, false )
  323. change_integer_list( pi_device_type_values,
  324. ppsz_device_type_descriptions )
  325. #if defined(WIN32)
  326. add_string(CFG_PREFIX "serialdev", "COM1",
  327. SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  328. /*
  329. on win32 the executeable external driver application
  330. for automatic start if needed
  331. */
  332. add_loadfile(CFG_PREFIX "atmowinexe", NULL,
  333. ATMOWINEXE_TEXT, ATMOWINEXE_LONGTEXT, false )
  334. #else
  335. add_string(CFG_PREFIX "serialdev", "/dev/ttyUSB0",
  336. SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  337. #endif
  338. /*
  339. color which is showed if you want durring pausing
  340. your movie ... used for both buildin / external
  341. */
  342. set_section( N_("Illuminate the room with this color on pause" ), 0 )
  343. add_bool(CFG_PREFIX "usepausecolor", false,
  344. PCOLOR_TEXT, PCOLOR_LONGTEXT, false)
  345. add_integer_with_range(CFG_PREFIX "pcolor-red", 0, 0, 255,
  346. PCOLOR_RED_TEXT, PCOLOR_RED_LONGTEXT, false)
  347. add_integer_with_range(CFG_PREFIX "pcolor-green", 0, 0, 255,
  348. PCOLOR_GREEN_TEXT, PCOLOR_GREEN_LONGTEXT, false)
  349. add_integer_with_range(CFG_PREFIX "pcolor-blue", 192, 0, 255,
  350. PCOLOR_BLUE_TEXT, PCOLOR_BLUE_LONGTEXT, false)
  351. add_integer_with_range(CFG_PREFIX "fadesteps", 50, 1, 250,
  352. FADESTEPS_TEXT, FADESTEPS_LONGTEXT, false)
  353. /*
  354. color which is showed if you finished watching your movie ...
  355. used for both buildin / external
  356. */
  357. set_section( N_("Illuminate the room with this color on shutdown" ), 0 )
  358. add_integer_with_range(CFG_PREFIX "ecolor-red", 192, 0, 255,
  359. ECOLOR_RED_TEXT, ECOLOR_RED_LONGTEXT, false)
  360. add_integer_with_range(CFG_PREFIX "ecolor-green", 192, 0, 255,
  361. ECOLOR_GREEN_TEXT, ECOLOR_GREEN_LONGTEXT, false)
  362. add_integer_with_range(CFG_PREFIX "ecolor-blue", 192, 0, 255,
  363. ECOLOR_BLUE_TEXT, ECOLOR_BLUE_LONGTEXT, false)
  364. add_integer_with_range(CFG_PREFIX "efadesteps", 50, 1, 250,
  365. EFADESTEPS_TEXT, EFADESTEPS_LONGTEXT, false)
  366. set_section( N_("DMX options" ), 0 )
  367. add_integer_with_range(CFG_PREFIX "dmx-channels", 5, 1, 64,
  368. DMX_CHANNELS_TEXT, DMX_CHANNELS_LONGTEXT, false)
  369. add_string(CFG_PREFIX "dmx-chbase", "0,3,6,9,12",
  370. DMX_CHBASE_TEXT, DMX_CHBASE_LONGTEXT, false )
  371. set_section( N_("MoMoLight options" ), 0 )
  372. add_integer_with_range(CFG_PREFIX "momo-channels", 3, 3, 4,
  373. MOMO_CHANNELS_TEXT, MOMO_CHANNELS_LONGTEXT, false)
  374. /* 2,2,4 means 2 is the default value, 1 minimum amount,
  375. 4 maximum amount
  376. */
  377. set_section( N_("fnordlicht options" ), 0 )
  378. add_integer_with_range(CFG_PREFIX "fnordlicht-amount", 2, 1, 254,
  379. FNORDLICHT_AMOUNT_TEXT,
  380. FNORDLICHT_AMOUNT_LONGTEXT, false)
  381. /*
  382. instead of redefining the original AtmoLight zones with gradient
  383. bitmaps, we can now define the layout of the zones useing these
  384. parameters - the function with the gradient bitmaps would still
  385. work (but for most cases its no longer required)
  386. short description whats this means - f.e. the classic atmo would
  387. have this layout
  388. zones-top = 1 - zone 0
  389. zones-lr = 1 - zone 1 und zone 3
  390. zones-bottom = 1 - zone 2
  391. zone-summary = true - zone 4
  392. Z0
  393. ,------------,
  394. | |
  395. Z3| Z4 | Z1
  396. |____________|
  397. Z2
  398. the zone numbers will be counted clockwise starting at top / left
  399. if you want to split the light at the top, without having a bottom zone
  400. (which is my private config)
  401. zones-top = 2 - zone 0, zone 1
  402. zones-lr = 1 - zone 2 und zone 3
  403. zones-bottom = 0
  404. zone-summary = false
  405. Z0 Z1
  406. ,------------,
  407. | |
  408. Z3| | Z2
  409. |____________|
  410. */
  411. set_section( N_("Zone Layout for the build-in Atmo" ), 0 )
  412. add_integer_with_range(CFG_PREFIX "zones-top", 1, 0, 16,
  413. ZONE_TOP_TEXT, ZONE_TOP_LONGTEXT, false)
  414. add_integer_with_range(CFG_PREFIX "zones-bottom", 1, 0, 16,
  415. ZONE_BOTTOM_TEXT, ZONE_BOTTOM_LONGTEXT, false)
  416. add_integer_with_range(CFG_PREFIX "zones-lr", 1, 0, 16,
  417. ZONE_LR_TEXT, ZONE_LR_LONGTEXT, false)
  418. add_bool(CFG_PREFIX "zone-summary", false,
  419. ZONE_SUMMARY_TEXT, ZONE_SUMMARY_LONGTEXT, false)
  420. /*
  421. settings only for the buildin driver (if external driver app is used
  422. these parameters are ignored.)
  423. definition of parameters for the buildin filter ...
  424. */
  425. set_section( N_("Settings for the built-in Live Video Processor only" ), 0 )
  426. add_integer_with_range(CFG_PREFIX "edgeweightning", 3, 1, 30,
  427. EDGE_TEXT, EDGE_LONGTEXT, false)
  428. add_integer_with_range(CFG_PREFIX "brightness", 100, 50, 300,
  429. BRIGHTNESS_TEXT, BRIGHTNESS_LONGTEXT, false)
  430. add_integer_with_range(CFG_PREFIX "darknesslimit", 3, 0, 10,
  431. DARKNESS_TEXT, DARKNESS_LONGTEXT, false)
  432. add_integer_with_range(CFG_PREFIX "huewinsize", 3, 0, 5,
  433. HUEWINSIZE_TEXT, HUEWINSIZE_LONGTEXT, false)
  434. add_integer_with_range(CFG_PREFIX "satwinsize", 3, 0, 5,
  435. SATWINSIZE_TEXT, SATWINSIZE_LONGTEXT, false)
  436. add_integer(CFG_PREFIX "filtermode", (int)afmCombined,
  437. FILTERMODE_TEXT, FILTERMODE_LONGTEXT, false )
  438. change_integer_list(pi_filtermode_values, ppsz_filtermode_descriptions )
  439. add_integer_with_range(CFG_PREFIX "meanlength", 300, 300, 5000,
  440. MEANLENGTH_TEXT, MEANLENGTH_LONGTEXT, false)
  441. add_integer_with_range(CFG_PREFIX "meanthreshold", 40, 1, 100,
  442. MEANTHRESHOLD_TEXT, MEANTHRESHOLD_LONGTEXT, false)
  443. add_integer_with_range(CFG_PREFIX "percentnew", 50, 1, 100,
  444. MEANPERCENTNEW_TEXT, MEANPERCENTNEW_LONGTEXT, false)
  445. add_integer_with_range(CFG_PREFIX "framedelay", 18, 0, 200,
  446. FRAMEDELAY_TEXT, FRAMEDELAY_LONGTEXT, false)
  447. /*
  448. output channel reordering
  449. */
  450. set_section( N_("Change channel assignment (fixes wrong wiring)" ), 0 )
  451. add_integer( CFG_PREFIX "channel_0", 4,
  452. CHANNEL_0_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  453. change_integer_list( pi_zone_assignment_values,
  454. ppsz_zone_assignment_descriptions )
  455. add_integer( CFG_PREFIX "channel_1", 3,
  456. CHANNEL_1_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  457. change_integer_list( pi_zone_assignment_values,
  458. ppsz_zone_assignment_descriptions )
  459. add_integer( CFG_PREFIX "channel_2", 1,
  460. CHANNEL_2_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  461. change_integer_list( pi_zone_assignment_values,
  462. ppsz_zone_assignment_descriptions )
  463. add_integer( CFG_PREFIX "channel_3", 0,
  464. CHANNEL_3_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  465. change_integer_list( pi_zone_assignment_values,
  466. ppsz_zone_assignment_descriptions )
  467. add_integer( CFG_PREFIX "channel_4", 2,
  468. CHANNEL_4_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  469. change_integer_list( pi_zone_assignment_values,
  470. ppsz_zone_assignment_descriptions )
  471. add_string(CFG_PREFIX "channels", "",
  472. CHANNELS_ASSIGN_TEXT, CHANNELS_ASSIGN_LONGTEXT, false )
  473. /*
  474. LED color white calibration
  475. */
  476. set_section( N_("Adjust the white light to your LED stripes" ), 0 )
  477. add_bool(CFG_PREFIX "whiteadj", true,
  478. USEWHITEADJ_TEXT, USEWHITEADJ_LONGTEXT, false)
  479. add_integer_with_range(CFG_PREFIX "white-red", 255, 0, 255,
  480. WHITE_RED_TEXT, WHITE_RED_LONGTEXT, false)
  481. add_integer_with_range(CFG_PREFIX "white-green", 255, 0, 255,
  482. WHITE_GREEN_TEXT, WHITE_GREEN_LONGTEXT, false)
  483. add_integer_with_range(CFG_PREFIX "white-blue", 255, 0, 255,
  484. WHITE_BLUE_TEXT, WHITE_BLUE_LONGTEXT, false)
  485. /* end of definition of parameter for the buildin filter ... part 1 */
  486. /*
  487. only for buildin (external has own definition) per default the calucation
  488. used linear gradients for assigning a priority to the pixel - depending
  489. how near they are to the border ...for changing this you can create 64x48
  490. Pixel BMP files - which contain your own grayscale... (you can produce funny
  491. effects with this...) the images MUST not compressed, should have 24-bit per
  492. pixel, or a simple 256 color grayscale palette
  493. */
  494. set_section( N_("Change gradients" ), 0 )
  495. add_loadfile(CFG_PREFIX "gradient_zone_0", NULL,
  496. ZONE_0_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  497. add_loadfile(CFG_PREFIX "gradient_zone_1", NULL,
  498. ZONE_1_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  499. add_loadfile(CFG_PREFIX "gradient_zone_2", NULL,
  500. ZONE_2_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  501. add_loadfile(CFG_PREFIX "gradient_zone_3", NULL,
  502. ZONE_3_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  503. add_loadfile(CFG_PREFIX "gradient_zone_4", NULL,
  504. ZONE_4_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  505. add_directory(CFG_PREFIX "gradient_path", NULL,
  506. GRADIENT_PATH_TEXT, GRADIENT_PATH_LONGTEXT, false )
  507. #if defined(__ATMO_DEBUG__)
  508. add_bool(CFG_PREFIX "saveframes", false,
  509. SAVEFRAMES_TEXT, SAVEFRAMES_LONGTEXT, false)
  510. add_string(CFG_PREFIX "framepath", "",
  511. FRAMEPATH_TEXT, FRAMEPATH_LONGTEXT, false )
  512. #endif
  513. /*
  514. may be later if computers gets more power ;-) than now we increase
  515. the samplesize from which we do the stats for output color calculation
  516. */
  517. add_integer_with_range(CFG_PREFIX "width", 64, 64, 512,
  518. WIDTH_TEXT, WIDTH_LONGTEXT, true)
  519. add_integer_with_range(CFG_PREFIX "height", 48, 48, 384,
  520. HEIGHT_TEXT, HEIGHT_LONGTEXT, true)
  521. add_bool(CFG_PREFIX "showdots", false,
  522. SHOW_DOTS_TEXT, SHOW_DOTS_LONGTEXT, false)
  523. add_shortcut( "atmo" )
  524. set_callbacks( CreateFilter, DestroyFilter )
  525. vlc_module_end ()
  526. static const char *const ppsz_filter_options[] = {
  527. "device",
  528. "serialdev",
  529. "edgeweightning",
  530. "brightness",
  531. "darknesslimit",
  532. "huewinsize",
  533. "satwinsize",
  534. "filtermode",
  535. "meanlength",
  536. "meanthreshold",
  537. "percentnew",
  538. "framedelay",
  539. "zones-top",
  540. "zones-bottom",
  541. "zones-lr",
  542. "zone-summary",
  543. "channel_0",
  544. "channel_1",
  545. "channel_2",
  546. "channel_3",
  547. "channel_4",
  548. "channels",
  549. "whiteadj",
  550. "white-red",
  551. "white-green",
  552. "white-blue",
  553. "usepausecolor",
  554. "pcolor-red",
  555. "pcolor-green",
  556. "pcolor-blue",
  557. "fadesteps",
  558. "ecolor-red",
  559. "ecolor-green",
  560. "ecolor-blue",
  561. "efadesteps",
  562. "dmx-channels",
  563. "dmx-chbase",
  564. "momo-channels",
  565. "fnordlicht-amount",
  566. #if defined(WIN32 )
  567. "atmowinexe",
  568. #endif
  569. #if defined(__ATMO_DEBUG__)
  570. "saveframes" ,
  571. "framepath",
  572. #endif
  573. "width",
  574. "height",
  575. "showdots",
  576. "gradient_zone_0",
  577. "gradient_zone_1",
  578. "gradient_zone_2",
  579. "gradient_zone_3",
  580. "gradient_zone_4",
  581. "gradient_path",
  582. NULL
  583. };
  584. /*****************************************************************************
  585. * fadethread_t: Color Fading Thread
  586. *****************************************************************************
  587. * changes slowly the color of the output if videostream gets paused...
  588. *****************************************************************************
  589. */
  590. typedef struct
  591. {
  592. filter_t *p_filter;
  593. vlc_thread_t thread;
  594. vlc_atomic_t abort;
  595. /* tell the thread which color should be the target of fading */
  596. uint8_t ui_red;
  597. uint8_t ui_green;
  598. uint8_t ui_blue;
  599. /* how many steps should happen until this */
  600. int i_steps;
  601. } fadethread_t;
  602. static void *FadeToColorThread(void *);
  603. /*****************************************************************************
  604. * filter_sys_t: AtmoLight filter method descriptor
  605. *****************************************************************************
  606. * It describes the AtmoLight specific properties of an video filter.
  607. *****************************************************************************/
  608. struct filter_sys_t
  609. {
  610. /*
  611. special for the access of the p_fadethread member all other members
  612. need no special protection so far!
  613. */
  614. vlc_mutex_t filter_lock;
  615. bool b_enabled;
  616. int32_t i_AtmoOldEffect;
  617. bool b_pause_live;
  618. bool b_show_dots;
  619. int32_t i_device_type;
  620. bool b_swap_uv;
  621. int32_t i_atmo_width;
  622. int32_t i_atmo_height;
  623. /* used to disable fadeout if less than 50 frames are processed
  624. used to avoid long time waiting when switch quickly between
  625. deinterlaceing modes, where the output filter chains is rebuild
  626. on each switch
  627. */
  628. int32_t i_frames_processed;
  629. #if defined(__ATMO_DEBUG__)
  630. bool b_saveframes;
  631. uint32_t ui_frame_counter;
  632. char sz_framepath[MAX_PATH];
  633. #endif
  634. /* light color durring movie pause ... */
  635. bool b_usepausecolor;
  636. uint8_t ui_pausecolor_red;
  637. uint8_t ui_pausecolor_green;
  638. uint8_t ui_pausecolor_blue;
  639. int i_fadesteps;
  640. /* light color on movie finish ... */
  641. uint8_t ui_endcolor_red;
  642. uint8_t ui_endcolor_green;
  643. uint8_t ui_endcolor_blue;
  644. int i_endfadesteps;
  645. fadethread_t *p_fadethread;
  646. /* Variables for buildin driver only... */
  647. /* is only present and initialized if the internal driver is used*/
  648. CAtmoConfig *p_atmo_config;
  649. /* storage for temporal settings "volatile" */
  650. CAtmoDynData *p_atmo_dyndata;
  651. /* initialized for buildin driver with AtmoCreateTransferBuffers */
  652. BITMAPINFOHEADER mini_image_format;
  653. /* is only use buildin driver! */
  654. uint8_t *p_atmo_transfer_buffer;
  655. /* end buildin driver */
  656. /*
  657. contains the real output size of the video calculated on
  658. change event of the variable "crop" from vout
  659. */
  660. int32_t i_crop_x_offset;
  661. int32_t i_crop_y_offset;
  662. int32_t i_crop_width;
  663. int32_t i_crop_height;
  664. void (*pf_extract_mini_image) (filter_sys_t *p_sys,
  665. picture_t *p_inpic,
  666. uint8_t *p_transfer_dest);
  667. #if defined( WIN32 )
  668. /* External Library as wrapper arround COM Stuff */
  669. HINSTANCE h_AtmoCtrl;
  670. int32_t (*pf_ctrl_atmo_initialize) (void);
  671. void (*pf_ctrl_atmo_finalize) (int32_t what);
  672. int32_t (*pf_ctrl_atmo_switch_effect) (int32_t);
  673. int32_t (*pf_ctrl_atmo_set_live_source) (int32_t);
  674. void (*pf_ctrl_atmo_create_transfer_buffers) (int32_t, int32_t,
  675. int32_t , int32_t);
  676. uint8_t* (*pf_ctrl_atmo_lock_transfer_buffer) (void);
  677. void (*pf_ctrl_atmo_send_pixel_data) (void);
  678. void (*pf_ctrl_atmo_get_image_size)(int32_t *,int32_t *);
  679. #endif
  680. };
  681. /*
  682. initialize previously configured Atmo Light environment
  683. - if internal is enabled try to access the device on the serial port
  684. - if not internal is enabled and we are on win32 try to initialize
  685. the previously loaded DLL ...
  686. Return Values may be: -1 (failed for some reason - filter will be disabled)
  687. 1 Ok. lets rock
  688. */
  689. static int32_t AtmoInitialize(filter_t *p_filter, bool b_for_thread)
  690. {
  691. filter_sys_t *p_sys = p_filter->p_sys;
  692. if(p_sys->p_atmo_config)
  693. {
  694. if(!b_for_thread)
  695. {
  696. /* open com port */
  697. /* setup Output Threads ... */
  698. msg_Dbg( p_filter, "open atmo device...");
  699. if(CAtmoTools::RecreateConnection(p_sys->p_atmo_dyndata)
  700. == ATMO_TRUE)
  701. {
  702. return 1;
  703. } else {
  704. msg_Err( p_filter,"failed to open atmo device, "\
  705. "some other software/driver may use it?");
  706. }
  707. }
  708. #if defined(WIN32)
  709. } else if(p_sys->pf_ctrl_atmo_initialize)
  710. {
  711. /* on win32 with active ctrl dll */
  712. return p_sys->pf_ctrl_atmo_initialize();
  713. #endif
  714. }
  715. return -1;
  716. }
  717. /*
  718. prepare the shutdown of the effect threads,
  719. for build in filter - close the serialport after finishing the threads...
  720. cleanup possible loaded DLL...
  721. */
  722. static void AtmoFinalize(filter_t *p_filter, int32_t what)
  723. {
  724. filter_sys_t *p_sys = p_filter->p_sys;
  725. if(p_sys->p_atmo_config)
  726. {
  727. if(what == 1)
  728. {
  729. CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  730. if(p_atmo_dyndata)
  731. {
  732. p_atmo_dyndata->LockCriticalSection();
  733. CAtmoInput *p_input = p_atmo_dyndata->getLiveInput();
  734. p_atmo_dyndata->setLiveInput( NULL );
  735. if(p_input != NULL)
  736. {
  737. p_input->Terminate();
  738. delete p_input;
  739. msg_Dbg( p_filter, "input thread died peacefully");
  740. }
  741. CThread *p_effect_thread = p_atmo_dyndata->getEffectThread();
  742. p_atmo_dyndata->setEffectThread(NULL);
  743. if(p_effect_thread != NULL)
  744. {
  745. /*
  746. forced the thread to die...
  747. and wait for termination of the thread
  748. */
  749. p_effect_thread->Terminate();
  750. delete p_effect_thread;
  751. msg_Dbg( p_filter, "effect thread died peacefully");
  752. }
  753. CAtmoPacketQueue *p_queue =
  754. p_atmo_dyndata->getLivePacketQueue();
  755. p_atmo_dyndata->setLivePacketQueue( NULL );
  756. if(p_queue != NULL)
  757. {
  758. delete p_queue;
  759. msg_Dbg( p_filter, "packetqueue removed");
  760. }
  761. /*
  762. close serial port if it is open (all OS specific is inside
  763. CAtmoSerialConnection implemented / defined)
  764. */
  765. CAtmoConnection *p_atmo_connection =
  766. p_atmo_dyndata->getAtmoConnection();
  767. p_atmo_dyndata->setAtmoConnection(NULL);
  768. if(p_atmo_connection) {
  769. p_atmo_connection->CloseConnection();
  770. delete p_atmo_connection;
  771. }
  772. p_atmo_dyndata->UnLockCriticalSection();
  773. }
  774. }
  775. #if defined(WIN32)
  776. } else if(p_sys->pf_ctrl_atmo_finalize)
  777. {
  778. /* on win32 with active ctrl dll */
  779. p_sys->pf_ctrl_atmo_finalize(what);
  780. #endif
  781. }
  782. }
  783. /*
  784. switch the current light effect to LiveView
  785. */
  786. static int32_t AtmoSwitchEffect(filter_t *p_filter, int32_t newMode)
  787. {
  788. filter_sys_t *p_sys = p_filter->p_sys;
  789. msg_Dbg( p_filter, "AtmoSwitchEffect %d", newMode );
  790. if(p_sys->p_atmo_config)
  791. {
  792. return CAtmoTools::SwitchEffect(p_sys->p_atmo_dyndata, emLivePicture);
  793. #if defined(WIN32)
  794. } else if(p_sys->pf_ctrl_atmo_switch_effect)
  795. {
  796. /* on win32 with active ctrl dll */
  797. return p_sys->pf_ctrl_atmo_switch_effect( newMode );
  798. #endif
  799. }
  800. return emDisabled;
  801. }
  802. /*
  803. set the current live picture source, does only something on win32,
  804. with the external libraries - if the buildin effects are used nothing
  805. happens...
  806. */
  807. static int32_t AtmoSetLiveSource(filter_t *p_filter, int32_t newSource)
  808. {
  809. filter_sys_t *p_sys = p_filter->p_sys;
  810. msg_Dbg( p_filter, "AtmoSetLiveSource %d", newSource );
  811. if(p_sys->p_atmo_config)
  812. {
  813. /*
  814. buildin driver
  815. doesnt know different sources so this
  816. function call would just do nothing special
  817. in this case
  818. */
  819. #if defined(WIN32)
  820. } else if(p_sys->pf_ctrl_atmo_set_live_source)
  821. {
  822. /* on win32 with active ctrl dll */
  823. return p_sys->pf_ctrl_atmo_set_live_source(newSource);
  824. #endif
  825. }
  826. return lvsGDI;
  827. }
  828. /*
  829. setup the pixel transferbuffers which is used to transfer pixeldata from
  830. the filter to the effect thread, and possible accross the process
  831. boundaries on win32, with the external DLL
  832. */
  833. static void AtmoCreateTransferBuffers(filter_t *p_filter,
  834. int32_t FourCC,
  835. int32_t bytePerPixel,
  836. int32_t width,
  837. int32_t height)
  838. {
  839. filter_sys_t *p_sys = p_filter->p_sys;
  840. if(p_sys->p_atmo_config)
  841. {
  842. /*
  843. we need a buffer where the image is stored (only for transfer
  844. to the processing thread)
  845. */
  846. free( p_sys->p_atmo_transfer_buffer );
  847. p_sys->p_atmo_transfer_buffer = (uint8_t *)malloc(bytePerPixel *
  848. width * height);
  849. memset(&p_sys->mini_image_format,0,sizeof(BITMAPINFOHEADER));
  850. p_sys->mini_image_format.biSize = sizeof(BITMAPINFOHEADER);
  851. p_sys->mini_image_format.biWidth = width;
  852. p_sys->mini_image_format.biHeight = height;
  853. p_sys->mini_image_format.biBitCount = bytePerPixel*8;
  854. p_sys->mini_image_format.biCompression = FourCC;
  855. #if defined(WIN32)
  856. } else if(p_sys->pf_ctrl_atmo_create_transfer_buffers)
  857. {
  858. /* on win32 with active ctrl dll */
  859. p_sys->pf_ctrl_atmo_create_transfer_buffers(FourCC,
  860. bytePerPixel,
  861. width,
  862. height);
  863. #endif
  864. }
  865. }
  866. /*
  867. acquire the transfer buffer pointer the buildin version only
  868. returns the pointer to the allocated buffer ... the
  869. external version on win32 has to do some COM stuff to lock the
  870. Variant Byte array which is behind the buffer
  871. */
  872. static uint8_t* AtmoLockTransferBuffer(filter_t *p_filter)
  873. {
  874. filter_sys_t *p_sys = p_filter->p_sys;
  875. if(p_sys->p_atmo_config)
  876. {
  877. return p_sys->p_atmo_transfer_buffer;
  878. #if defined(WIN32)
  879. } else if(p_sys->pf_ctrl_atmo_lock_transfer_buffer)
  880. {
  881. /* on win32 with active ctrl dll */
  882. return p_sys->pf_ctrl_atmo_lock_transfer_buffer();
  883. #endif
  884. }
  885. return NULL;
  886. }
  887. /*
  888. send the content of current pixel buffer got with AtmoLockTransferBuffer
  889. to the processing threads
  890. - build in version - will forward the data to AtmoExternalCaptureInput Thread
  891. - win32 external - will do the same, but across the process boundaries via
  892. COM to the AtmoWinA.exe Process
  893. */
  894. static void AtmoSendPixelData(filter_t *p_filter)
  895. {
  896. filter_sys_t *p_sys = p_filter->p_sys;
  897. if(p_sys->p_atmo_config && p_sys->p_atmo_transfer_buffer)
  898. {
  899. CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  900. if(p_atmo_dyndata &&
  901. (p_atmo_dyndata->getLivePictureSource() == lpsExtern))
  902. {
  903. /*
  904. the cast will go Ok because we are inside videolan there is only
  905. this kind of effect thread implemented!
  906. */
  907. CAtmoExternalCaptureInput *p_atmo_external_capture_input_thread =
  908. (CAtmoExternalCaptureInput *)p_atmo_dyndata->getLiveInput();
  909. if(p_atmo_external_capture_input_thread)
  910. {
  911. /*
  912. the same as above inside videolan only this single kind of
  913. input exists so we can cast without further tests!
  914. this call will do a 1:1 copy of this buffer, and wakeup
  915. the thread from normal sleeping
  916. */
  917. p_atmo_external_capture_input_thread->
  918. DeliverNewSourceDataPaket(&p_sys->mini_image_format,
  919. p_sys->p_atmo_transfer_buffer);
  920. }
  921. }
  922. #if defined(WIN32)
  923. } else if(p_sys->pf_ctrl_atmo_send_pixel_data)
  924. {
  925. /* on win32 with active ctrl dll */
  926. p_sys->pf_ctrl_atmo_send_pixel_data();
  927. #endif
  928. } else
  929. {
  930. msg_Warn( p_filter, "AtmoSendPixelData no method");
  931. }
  932. }
  933. /*
  934. Shutdown AtmoLight finally - is call from DestroyFilter
  935. does the cleanup restores the effectmode on the external Software
  936. (only win32) and possible setup the final light ...
  937. */
  938. static void Atmo_Shutdown(filter_t *p_filter)
  939. {
  940. filter_sys_t *p_sys = p_filter->p_sys;
  941. if(p_sys->b_enabled)
  942. {
  943. msg_Dbg( p_filter, "shut down atmo!");
  944. /*
  945. if there is a still running show pause color thread kill him!
  946. */
  947. CheckAndStopFadeThread(p_filter);
  948. // perpare spawn fadeing thread
  949. vlc_mutex_lock( &p_sys->filter_lock );
  950. /*
  951. fade to end color (in case of external AtmoWin Software
  952. assume that the static color will equal to this
  953. one to get a soft change and no flash!
  954. */
  955. p_sys->b_pause_live = true;
  956. p_sys->p_fadethread = (fadethread_t *)calloc( 1, sizeof(fadethread_t) );
  957. p_sys->p_fadethread->p_filter = p_filter;
  958. p_sys->p_fadethread->ui_red = p_sys->ui_endcolor_red;
  959. p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green;
  960. p_sys->p_fadethread->ui_blue = p_sys->ui_endcolor_blue;
  961. if(p_sys->i_frames_processed < 50)
  962. p_sys->p_fadethread->i_steps = 1;
  963. else
  964. p_sys->p_fadethread->i_steps = p_sys->i_endfadesteps;
  965. vlc_atomic_set(&p_sys->p_fadethread->abort, 0);
  966. if( vlc_clone( &p_sys->p_fadethread->thread,
  967. FadeToColorThread,
  968. p_sys->p_fadethread,
  969. VLC_THREAD_PRIORITY_LOW ) )
  970. {
  971. msg_Err( p_filter, "cannot create FadeToColorThread" );
  972. free( p_sys->p_fadethread );
  973. p_sys->p_fadethread = NULL;
  974. vlc_mutex_unlock( &p_sys->filter_lock );
  975. } else {
  976. vlc_mutex_unlock( &p_sys->filter_lock );
  977. /* wait for the thread... */
  978. vlc_join(p_sys->p_fadethread->thread, NULL);
  979. free(p_sys->p_fadethread);
  980. p_sys->p_fadethread = NULL;
  981. }
  982. /*
  983. the following happens only useing the
  984. external AtmoWin Device Software
  985. */
  986. if( !p_sys->p_atmo_config )
  987. {
  988. if(p_sys->i_AtmoOldEffect != emLivePicture)
  989. AtmoSwitchEffect( p_filter, p_sys->i_AtmoOldEffect);
  990. else
  991. AtmoSetLiveSource( p_filter, lvsGDI );
  992. }
  993. /* close device connection etc. */
  994. AtmoFinalize(p_filter, 1);
  995. /* disable filter method .. */
  996. p_sys->b_enabled = false;
  997. }
  998. }
  999. /*
  1000. depending on mode setup imagesize to 64x48(classic), or defined
  1001. resolution of external atmowin.exe on windows
  1002. */
  1003. static void Atmo_SetupImageSize(filter_t *p_filter)
  1004. {
  1005. filter_sys_t *p_sys = p_filter->p_sys;
  1006. /*
  1007. size of extracted image by default 64x48 (other imagesizes are
  1008. currently ignored by AtmoWin)
  1009. */
  1010. p_sys->i_atmo_width = var_CreateGetIntegerCommand( p_filter,
  1011. CFG_PREFIX "width");
  1012. p_sys->i_atmo_height = var_CreateGetIntegerCommand( p_filter,
  1013. CFG_PREFIX "height");
  1014. if(p_sys->p_atmo_config)
  1015. {
  1016. #if defined(WIN32)
  1017. } else if(p_sys->pf_ctrl_atmo_get_image_size)
  1018. {
  1019. /* on win32 with active ctrl dll */
  1020. p_sys->pf_ctrl_atmo_get_image_size( &p_sys->i_atmo_width,
  1021. &p_sys->i_atmo_height );
  1022. #endif
  1023. }
  1024. msg_Dbg(p_filter,"sample image size %d * %d pixels", p_sys->i_atmo_width,
  1025. p_sys->i_atmo_height);
  1026. }
  1027. /*
  1028. initialize the zone and channel mapping for the buildin atmolight adapter
  1029. */
  1030. static void Atmo_SetupBuildZones(filter_t *p_filter)
  1031. {
  1032. filter_sys_t *p_sys = p_filter->p_sys;
  1033. p_sys->p_atmo_dyndata->LockCriticalSection();
  1034. CAtmoConfig *p_atmo_config = p_sys->p_atmo_config;
  1035. CAtmoChannelAssignment *p_channel_assignment =
  1036. p_atmo_config->getChannelAssignment(0);
  1037. // channel 0 - zone 4
  1038. p_channel_assignment->setZoneIndex( 0, var_CreateGetIntegerCommand(
  1039. p_filter, CFG_PREFIX "channel_0")
  1040. );
  1041. // channel 1 - zone 3
  1042. p_channel_assignment->setZoneIndex( 1, var_CreateGetIntegerCommand(
  1043. p_filter, CFG_PREFIX "channel_1")
  1044. );
  1045. // channel 2 - zone 1
  1046. p_channel_assignment->setZoneIndex( 2, var_CreateGetIntegerCommand(
  1047. p_filter, CFG_PREFIX "channel_2")
  1048. );
  1049. // channel 3 - zone 0
  1050. p_channel_assignment->setZoneIndex( 3, var_CreateGetIntegerCommand(
  1051. p_filter, CFG_PREFIX "channel_3")
  1052. );
  1053. // channel 4 - zone 2
  1054. p_channel_assignment->setZoneIndex( 4, var_CreateGetIntegerCommand(
  1055. p_filter, CFG_PREFIX "channel_4")
  1056. );
  1057. char *psz_channels = var_CreateGetStringCommand(
  1058. p_filter,
  1059. CFG_PREFIX "channels"
  1060. );
  1061. if( !EMPTY_STR(psz_channels) )
  1062. {
  1063. msg_Dbg( p_filter, "deal with new zone mapping %s", psz_channels );
  1064. int channel = 0;
  1065. char *psz_temp = psz_channels;
  1066. char *psz_start = psz_temp;
  1067. while( *psz_temp )
  1068. {
  1069. if(*psz_temp == ',' || *psz_temp == ';')
  1070. {
  1071. *psz_temp = 0;
  1072. if(*psz_start)
  1073. {
  1074. int zone = atoi( psz_start );
  1075. if( zone < -1 ||
  1076. zone >= p_channel_assignment->getSize()) {
  1077. msg_Warn( p_filter, "Zone %d out of range -1..%d",
  1078. zone, p_channel_assignment->getSize()-1 );
  1079. } else {
  1080. p_channel_assignment->setZoneIndex( channel, zone );
  1081. channel++;
  1082. }
  1083. }
  1084. psz_start = psz_temp;
  1085. psz_start++;
  1086. }
  1087. psz_temp++;
  1088. }
  1089. /*
  1090. process the rest of the string
  1091. */
  1092. if( *psz_start && !*psz_temp )
  1093. {
  1094. int zone = atoi( psz_start );
  1095. if( zone < -1 ||
  1096. zone >= p_channel_assignment->getSize()) {
  1097. msg_Warn( p_filter, "Zone %d out of range -1..%d",
  1098. zone, p_channel_assignment->getSize()-1 );
  1099. } else {
  1100. p_channel_assignment->setZoneIndex( channel, zone );
  1101. }
  1102. }
  1103. }
  1104. free( psz_channels );
  1105. for(int i=0;i< p_channel_assignment->getSize() ;i++)
  1106. msg_Info( p_filter, "map zone %d to hardware channel %d",
  1107. p_channel_assignment->getZoneIndex( i ),
  1108. i
  1109. );
  1110. p_sys->p_atmo_dyndata->getAtmoConnection()
  1111. ->SetChannelAssignment( p_channel_assignment );
  1112. /*
  1113. calculate the default gradients for each zone!
  1114. depending on the zone layout set before, this now
  1115. supports also multiple gradients on each side
  1116. (older versions could do this only with external
  1117. gradient bitmaps)
  1118. */
  1119. p_sys->p_atmo_dyndata->CalculateDefaultZones();
  1120. /*
  1121. first try to load the old style defined gradient bitmaps
  1122. this could only be done for the first five zones
  1123. - should be deprecated -
  1124. */
  1125. CAtmoZoneDefinition *p_zone;
  1126. char psz_gradient_var_name[30];
  1127. char *psz_gradient_file;
  1128. for(int i=0;i<CLASSIC_ATMO_NUM_ZONES;i++)
  1129. {
  1130. sprintf(psz_gradient_var_name, CFG_PREFIX "gradient_zone_%d", i);
  1131. psz_gradient_file = var_CreateGetStringCommand(
  1132. p_filter,
  1133. psz_gradient_var_name
  1134. );
  1135. if( !EMPTY_STR(psz_gradient_file) )
  1136. {
  1137. msg_Dbg( p_filter, "loading gradientfile %s for "\
  1138. "zone %d", psz_gradient_file, i);
  1139. p_zone = p_atmo_config->getZoneDefinition(i);
  1140. if( p_zone )
  1141. {
  1142. int i_res = p_zone->LoadGradientFromBitmap(psz_gradient_file);
  1143. if(i_res != ATMO_LOAD_GRADIENT_OK)
  1144. {
  1145. msg_Err( p_filter,"failed to load gradient '%s' with "\
  1146. "error %d",psz_gradient_file,i_res);
  1147. }
  1148. }
  1149. }
  1150. free( psz_gradient_file );
  1151. }
  1152. /*
  1153. the new approach try to load a gradient bitmap for each zone
  1154. from a previously defined folder containing
  1155. zone_0.bmp
  1156. zone_1.bmp
  1157. zone_2.bmp etc.
  1158. */
  1159. char *psz_gradient_path = var_CreateGetStringCommand(
  1160. p_filter,
  1161. CFG_PREFIX "gradient_path"
  1162. );
  1163. if( EMPTY_STR(psz_gradient_path) )
  1164. {
  1165. char *psz_file_name = (char *)malloc( strlen(psz_gradient_path) + 16 );
  1166. assert( psz_file_name );
  1167. for(int i=0; i < p_atmo_config->getZoneCount(); i++ )
  1168. {
  1169. p_zone = p_atmo_config->getZoneDefinition(i);
  1170. if( p_zone )
  1171. {
  1172. sprintf(psz_file_name, "%s%szone_%d.bmp",
  1173. psz_gradient_path, DIR_SEP, i );
  1174. int i_res = p_zone->LoadGradientFromBitmap( psz_file_name );
  1175. if( i_res == ATMO_LOAD_GRADIENT_OK )
  1176. {
  1177. msg_Dbg( p_filter, "loaded gradientfile %s for "\
  1178. "zone %d", psz_file_name, i);
  1179. }
  1180. if( (i_res != ATMO_LOAD_GRADIENT_OK) &&
  1181. (i_res != ATMO_LOAD_GRADIENT_FILENOTFOND) )
  1182. {
  1183. msg_Err( p_filter,"failed to load gradient '%s' with "\
  1184. "error %d",psz_file_name,i_res);
  1185. }
  1186. }
  1187. }
  1188. free( psz_file_name );
  1189. }
  1190. free( psz_gradient_path );
  1191. p_sys->p_atmo_dyndata->UnLockCriticalSection();
  1192. }
  1193. static void Atmo_SetupConfig(filter_t *p_filter, CAtmoConfig *p_atmo_config)
  1194. {
  1195. /*
  1196. figuring out the device ports (com-ports, ttys)
  1197. */
  1198. char *psz_serialdev = var_CreateGetSt

Large files files are truncated, but you can click here to view the full file