PageRenderTime 462ms CodeModel.GetById 232ms RepoModel.GetById 4ms app.codeStats 0ms

/ImportedSources/vlc/modules/video_filter/atmo/atmo.cpp

https://bitbucket.org/erndev/dreambox-live
C++ | 2827 lines | 1804 code | 432 blank | 591 comment | 229 complexity | 1567ae33e47c0f83325cc129e406fec1 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, WTFPL, LGPL-2.0, GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0
  1. /*****************************************************************************
  2. * atmo.cpp : "Atmo Light" video filter
  3. *****************************************************************************
  4. * Copyright (C) 2000-2006 the VideoLAN team
  5. * $Id: 1145e0e2266bda71e1d28c2b1468ee99b5dcc31a $
  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. /*****************************************************************************
  24. * Preamble
  25. *****************************************************************************/
  26. #define __STDC_FORMAT_MACROS 1
  27. #include <stdlib.h> /* malloc(), free() */
  28. #include <string.h>
  29. #include <math.h> /* sin(), cos() */
  30. #include <assert.h>
  31. #ifdef HAVE_CONFIG_H
  32. # include "config.h"
  33. #endif
  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 "filter_picture.h"
  42. #include "AtmoDefs.h"
  43. #include "AtmoDynData.h"
  44. #include "AtmoLiveView.h"
  45. #include "AtmoTools.h"
  46. #include "AtmoExternalCaptureInput.h"
  47. #include "AtmoConfig.h"
  48. #include "AtmoConnection.h"
  49. #include "AtmoClassicConnection.h"
  50. /*****************************************************************************
  51. * Local prototypes
  52. *****************************************************************************/
  53. /* directly to vlc related functions required that the module is accepted */
  54. static int CreateFilter ( vlc_object_t * );
  55. static void DestroyFilter ( vlc_object_t * );
  56. static picture_t * Filter( filter_t *, picture_t *);
  57. /* callback for global variable state pause / continue / stop events */
  58. static void AddStateVariableCallback( filter_t *);
  59. static void DelStateVariableCallback( filter_t *);
  60. static int StateCallback(vlc_object_t *, char const *,
  61. vlc_value_t, vlc_value_t, void *);
  62. /* callback for atmo settings variables whose change
  63. should be immediately realized and applied to output
  64. */
  65. static void DelAtmoSettingsVariablesCallbacks(filter_t *);
  66. static void AddAtmoSettingsVariablesCallbacks(filter_t *);
  67. static int AtmoSettingsCallback(vlc_object_t *, char const *,
  68. vlc_value_t, vlc_value_t, void *);
  69. #if defined(__ATMO_DEBUG__)
  70. static void atmo_parse_crop(char *psz_cropconfig,
  71. video_format_t fmt_in,
  72. video_format_t fmt_render,
  73. int &i_visible_width,
  74. int &i_visible_height,
  75. int &i_x_offset,
  76. int &i_y_offset );
  77. #endif
  78. /* function to shutdown the fade thread which is started on pause*/
  79. static void CheckAndStopFadeThread(filter_t *);
  80. /* extracts a small RGB (BGR) Image from an YUV image */
  81. static void ExtractMiniImage_YUV(filter_sys_t *, picture_t *, uint8_t *);
  82. #if defined(__ATMO_DEBUG__)
  83. void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename);
  84. #endif
  85. /*****************************************************************************
  86. * External Prototypes for the AtmoCtrlLib.DLL
  87. *****************************************************************************/
  88. /*
  89. * if effectmode = emLivePicture then the source could be GDI (Screencapture)
  90. * or External - this means another application delivers Pixeldata to AtmoWin
  91. * Clientsoftware through AtmoCtrlLib.DLL and the COM Api
  92. */
  93. #define lvsGDI 0
  94. #define lvsExternal 1
  95. #define CLASSIC_ATMO_NUM_ZONES 5
  96. /*
  97. strings for settings menus and hints
  98. */
  99. #define MODULE_DESCRIPTION N_ ( \
  100. "This module allows to control an so called AtmoLight device "\
  101. "connected to your computer.\n"\
  102. "AtmoLight is the homegrown version of what Philips calls AmbiLight.\n"\
  103. "If you need further information feel free to visit us at\n\n"\
  104. "http://www.vdr-wiki.de/wiki/index.php/Atmo-plugin\n"\
  105. "http://www.vdr-wiki.de/wiki/index.php/AtmoWin\n\n"\
  106. "You can find there detailed descriptions on how to build it for yourself "\
  107. "and where to get the required parts.\n" \
  108. "You can also have a look at pictures and some movies showing such a device " \
  109. "in live action.")
  110. #define DRIVER_TEXT N_("Device type")
  111. #define DRIVER_LONGTEXT N_("Choose your preferred hardware from " \
  112. "the list, or choose AtmoWin Software " \
  113. "to delegate processing to the external " \
  114. "process - with more options")
  115. static const int pi_device_type_values[] = {
  116. #if defined( WIN32 )
  117. 0, /* use AtmoWinA.exe userspace driver */
  118. #endif
  119. 1, /* AtmoLight classic */
  120. 2, /* Quattro AtmoLight */
  121. 3, /* DMX Device */
  122. 4, /* MoMoLight device */
  123. 5 /* fnordlicht */
  124. };
  125. static const char *const ppsz_device_type_descriptions[] = {
  126. #if defined( WIN32 )
  127. N_("AtmoWin Software"),
  128. #endif
  129. N_("Classic AtmoLight"),
  130. N_("Quattro AtmoLight"),
  131. N_("DMX"),
  132. N_("MoMoLight"),
  133. N_("fnordlicht")
  134. };
  135. #define DMX_CHANNELS_TEXT N_("Count of AtmoLight channels")
  136. #define DMX_CHANNELS_LONGTEXT N_("How many AtmoLight channels, should be " \
  137. "emulated with that DMX device")
  138. #define DMX_CHBASE_TEXT N_("DMX address for each channel")
  139. #define DMX_CHBASE_LONGTEXT N_("Define here the DMX base address for each " \
  140. "channel use , or ; to separate the values")
  141. #define MOMO_CHANNELS_TEXT N_("Count of channels")
  142. #define MOMO_CHANNELS_LONGTEXT N_("Depending on your MoMoLight hardware " \
  143. "choose 3 or 4 channels")
  144. #define FNORDLICHT_AMOUNT_TEXT N_("Count of fnordlicht's")
  145. #define FNORDLICHT_AMOUNT_LONGTEXT N_("Depending on the amount your " \
  146. "fnordlicht hardware " \
  147. "choose 1 to 254 channels")
  148. #if defined( WIN32 )
  149. # define DEFAULT_DEVICE 0
  150. #else
  151. # define DEFAULT_DEVICE 1
  152. #endif
  153. #if defined( __ATMO_DEBUG__ )
  154. # define SAVEFRAMES_TEXT N_("Save Debug Frames")
  155. # define SAVEFRAMES_LONGTEXT N_("Write every 128th miniframe to a folder.")
  156. # define FRAMEPATH_TEXT N_("Debug Frame Folder")
  157. # define FRAMEPATH_LONGTEXT N_("The path where the debugframes " \
  158. "should be saved")
  159. #endif
  160. #define WIDTH_TEXT N_("Extracted Image Width")
  161. #define WIDTH_LONGTEXT N_("The width of the mini image for " \
  162. "further processing (64 is default)")
  163. #define HEIGHT_TEXT N_("Extracted Image Height")
  164. #define HEIGHT_LONGTEXT N_("The height of the mini image for " \
  165. "further processing (48 is default)")
  166. #define SHOW_DOTS_TEXT N_("Mark analyzed pixels")
  167. #define SHOW_DOTS_LONGTEXT N_("makes the sample grid visible on screen as "\
  168. "white pixels")
  169. #define PCOLOR_TEXT N_("Color when paused")
  170. #define PCOLOR_LONGTEXT N_("Set the color to show if the user " \
  171. "pauses the video. (Have light to get " \
  172. "another beer?)")
  173. #define PCOLOR_RED_TEXT N_("Pause-Red")
  174. #define PCOLOR_RED_LONGTEXT N_("Red component of the pause color")
  175. #define PCOLOR_GREEN_TEXT N_("Pause-Green")
  176. #define PCOLOR_GREEN_LONGTEXT N_("Green component of the pause color")
  177. #define PCOLOR_BLUE_TEXT N_("Pause-Blue")
  178. #define PCOLOR_BLUE_LONGTEXT N_("Blue component of the pause color")
  179. #define FADESTEPS_TEXT N_("Pause-Fadesteps")
  180. #define FADESTEPS_LONGTEXT N_("Number of steps to change current color " \
  181. "to pause color (each step takes 40ms)")
  182. #define ECOLOR_RED_TEXT N_("End-Red")
  183. #define ECOLOR_RED_LONGTEXT N_("Red component of the shutdown color")
  184. #define ECOLOR_GREEN_TEXT N_("End-Green")
  185. #define ECOLOR_GREEN_LONGTEXT N_("Green component of the shutdown color")
  186. #define ECOLOR_BLUE_TEXT N_("End-Blue")
  187. #define ECOLOR_BLUE_LONGTEXT N_("Blue component of the shutdown color")
  188. #define EFADESTEPS_TEXT N_("End-Fadesteps")
  189. #define EFADESTEPS_LONGTEXT N_("Number of steps to change current color to " \
  190. "end color for dimming up the light in cinema " \
  191. "style... (each step takes 40ms)")
  192. #define ZONE_TOP_TEXT N_("Number of zones on top")
  193. #define ZONE_TOP_LONGTEXT N_("Number of zones on the top of the screen")
  194. #define ZONE_BOTTOM_TEXT N_("Number of zones on bottom")
  195. #define ZONE_BOTTOM_LONGTEXT N_("Number of zones on the bottom of the screen")
  196. #define ZONE_LR_TEXT N_("Zones on left / right side")
  197. #define ZONE_LR_LONGTEXT N_("left and right side having allways the " \
  198. "same number of zones")
  199. #define ZONE_SUMMARY_TEXT N_("Calculate a average zone")
  200. #define ZONE_SUMMARY_LONGTEXT N_("it contains the average of all pixels " \
  201. "in the sample image (only useful for " \
  202. "single channel AtmoLight)")
  203. #define USEWHITEADJ_TEXT N_("Use Software White adjust")
  204. #define USEWHITEADJ_LONGTEXT N_("Should the buildin driver do a white " \
  205. "adjust or your LED stripes? recommend.")
  206. #define WHITE_RED_TEXT N_("White Red")
  207. #define WHITE_RED_LONGTEXT N_("Red value of a pure white on your "\
  208. "LED stripes.")
  209. #define WHITE_GREEN_TEXT N_("White Green")
  210. #define WHITE_GREEN_LONGTEXT N_("Green value of a pure white on your "\
  211. "LED stripes.")
  212. #define WHITE_BLUE_TEXT N_("White Blue")
  213. #define WHITE_BLUE_LONGTEXT N_("Blue value of a pure white on your "\
  214. "LED stripes.")
  215. #define SERIALDEV_TEXT N_("Serial Port/Device")
  216. #define SERIALDEV_LONGTEXT N_("Name of the serial port where the AtmoLight "\
  217. "controller is attached to.\n" \
  218. "On Windows usually something like COM1 or " \
  219. "COM2. On Linux /dev/ttyS01 f.e.")
  220. #define EDGE_TEXT N_("Edge Weightning")
  221. #define EDGE_LONGTEXT N_("Increasing this value will result in color "\
  222. "more depending on the border of the frame.")
  223. #define BRIGHTNESS_TEXT N_("Brightness")
  224. #define BRIGHTNESS_LONGTEXT N_("Overall brightness of your LED stripes")
  225. #define DARKNESS_TEXT N_("Darkness Limit")
  226. #define DARKNESS_LONGTEXT N_("Pixels with a saturation lower than this will "\
  227. "be ignored. Should be greater than one for "\
  228. "letterboxed videos.")
  229. #define HUEWINSIZE_TEXT N_("Hue windowing")
  230. #define HUEWINSIZE_LONGTEXT N_("Used for statistics.")
  231. #define SATWINSIZE_TEXT N_("Sat windowing")
  232. #define SATWINSIZE_LONGTEXT N_("Used for statistics.")
  233. #define MEANLENGTH_TEXT N_("Filter length (ms)")
  234. #define MEANLENGTH_LONGTEXT N_("Time it takes until a color is completely "\
  235. "changed. This prevents flickering.")
  236. #define MEANTHRESHOLD_TEXT N_("Filter threshold")
  237. #define MEANTHRESHOLD_LONGTEXT N_("How much a color has to be changed for an "\
  238. "immediate color change.")
  239. #define MEANPERCENTNEW_TEXT N_("Filter Smoothness (in %)")
  240. #define MEANPERCENTNEW_LONGTEXT N_("Filter Smoothness")
  241. #define FILTERMODE_TEXT N_("Output Color filter mode")
  242. #define FILTERMODE_LONGTEXT N_("defines the how the output color should " \
  243. "be calculated based on previous color")
  244. static const int pi_filtermode_values[] = {
  245. (int)afmNoFilter,
  246. (int)afmCombined,
  247. (int)afmPercent
  248. };
  249. static const char *const ppsz_filtermode_descriptions[] = {
  250. N_("No Filtering"),
  251. N_("Combined"),
  252. N_("Percent")
  253. };
  254. #define FRAMEDELAY_TEXT N_("Frame delay (ms)")
  255. #define FRAMEDELAY_LONGTEXT N_("Helps to get the video output and the light "\
  256. "effects in sync. Values around 20ms should " \
  257. "do the trick.")
  258. #define CHANNEL_0_ASSIGN_TEXT N_("Channel 0: summary")
  259. #define CHANNEL_1_ASSIGN_TEXT N_("Channel 1: left")
  260. #define CHANNEL_2_ASSIGN_TEXT N_("Channel 2: right")
  261. #define CHANNEL_3_ASSIGN_TEXT N_("Channel 3: top")
  262. #define CHANNEL_4_ASSIGN_TEXT N_("Channel 4: bottom")
  263. #define CHANNELASSIGN_LONGTEXT N_("Maps the hardware channel X to logical "\
  264. "zone Y to fix wrong wiring :-)")
  265. static const int pi_zone_assignment_values[] = {
  266. -1,
  267. 4,
  268. 3,
  269. 1,
  270. 0,
  271. 2
  272. };
  273. static const char *const ppsz_zone_assignment_descriptions[] = {
  274. N_("disabled"),
  275. N_("Zone 4:summary"),
  276. N_("Zone 3:left"),
  277. N_("Zone 1:right"),
  278. N_("Zone 0:top"),
  279. N_("Zone 2:bottom")
  280. };
  281. #define CHANNELS_ASSIGN_TEXT N_("Channel / Zone Assignment")
  282. #define CHANNELS_ASSIGN_LONGTEXT N_("for devices with more than five " \
  283. "channels / zones write down here for each channel " \
  284. "the zone number to show and separate the values with " \
  285. ", or ; and use -1 to not use some channels. For the " \
  286. "classic AtmoLight the sequence 4,3,1,0,2 would set the " \
  287. "default channel/zone mapping. " \
  288. "Having only two zones on top, and one zone on left and " \
  289. "right and no summary zone the mapping for classic " \
  290. "AtmoLight would be -1,3,2,1,0")
  291. #define ZONE_0_GRADIENT_TEXT N_("Zone 0: Top gradient")
  292. #define ZONE_1_GRADIENT_TEXT N_("Zone 1: Right gradient")
  293. #define ZONE_2_GRADIENT_TEXT N_("Zone 2: Bottom gradient")
  294. #define ZONE_3_GRADIENT_TEXT N_("Zone 3: Left gradient")
  295. #define ZONE_4_GRADIENT_TEXT N_("Zone 4: Summary gradient")
  296. #define ZONE_X_GRADIENT_LONG_TEXT N_("Defines a small bitmap with 64x48 "\
  297. "pixels, containing a grayscale gradient")
  298. #define GRADIENT_PATH_TEXT N_("Gradient bitmap searchpath")
  299. #define GRADIENT_PATH_LONGTEXT N_("Now preferred option to assign gradient "\
  300. "bitmaps, put them as zone_0.bmp, zone_1.bmp etc. into one folder and "\
  301. "set the foldername here")
  302. #if defined( WIN32 )
  303. # define ATMOWINEXE_TEXT N_("Filename of AtmoWin*.exe")
  304. # define ATMOWINEXE_LONGTEXT N_("if you want the AtmoLight control "\
  305. "software to be launched by VLC, enter the "\
  306. "complete path of AtmoWinA.exe here.")
  307. #endif
  308. #define CFG_PREFIX "atmo-"
  309. /*****************************************************************************
  310. * Module descriptor
  311. *****************************************************************************/
  312. vlc_module_begin ()
  313. set_description( N_("AtmoLight Filter") )
  314. set_help( MODULE_DESCRIPTION )
  315. set_shortname( N_( "AtmoLight" ))
  316. set_category( CAT_VIDEO )
  317. set_subcategory( SUBCAT_VIDEO_VFILTER )
  318. set_capability( "video filter2", 0 )
  319. set_section( N_("Choose Devicetype and Connection" ), 0 )
  320. add_integer( CFG_PREFIX "device", DEFAULT_DEVICE,
  321. DRIVER_TEXT, DRIVER_LONGTEXT, false )
  322. change_integer_list( pi_device_type_values,
  323. ppsz_device_type_descriptions )
  324. #if defined(WIN32)
  325. add_string(CFG_PREFIX "serialdev", "COM1",
  326. SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  327. /*
  328. on win32 the executeable external driver application
  329. for automatic start if needed
  330. */
  331. add_loadfile(CFG_PREFIX "atmowinexe", NULL,
  332. ATMOWINEXE_TEXT, ATMOWINEXE_LONGTEXT, false )
  333. #else
  334. add_string(CFG_PREFIX "serialdev", "/dev/ttyUSB0",
  335. SERIALDEV_TEXT, SERIALDEV_LONGTEXT, false )
  336. #endif
  337. /*
  338. color which is showed if you want durring pausing
  339. your movie ... used for both buildin / external
  340. */
  341. set_section( N_("Illuminate the room with this color on pause" ), 0 )
  342. add_bool(CFG_PREFIX "usepausecolor", false,
  343. PCOLOR_TEXT, PCOLOR_LONGTEXT, false)
  344. add_integer_with_range(CFG_PREFIX "pcolor-red", 0, 0, 255, NULL,
  345. PCOLOR_RED_TEXT, PCOLOR_RED_LONGTEXT, false)
  346. add_integer_with_range(CFG_PREFIX "pcolor-green", 0, 0, 255, NULL,
  347. PCOLOR_GREEN_TEXT, PCOLOR_GREEN_LONGTEXT, false)
  348. add_integer_with_range(CFG_PREFIX "pcolor-blue", 192, 0, 255, NULL,
  349. PCOLOR_BLUE_TEXT, PCOLOR_BLUE_LONGTEXT, false)
  350. add_integer_with_range(CFG_PREFIX "fadesteps", 50, 1, 250, NULL,
  351. FADESTEPS_TEXT, FADESTEPS_LONGTEXT, false)
  352. /*
  353. color which is showed if you finished watching your movie ...
  354. used for both buildin / external
  355. */
  356. set_section( N_("Illuminate the room with this color on shutdown" ), 0 )
  357. add_integer_with_range(CFG_PREFIX "ecolor-red", 192, 0, 255, NULL,
  358. ECOLOR_RED_TEXT, ECOLOR_RED_LONGTEXT, false)
  359. add_integer_with_range(CFG_PREFIX "ecolor-green", 192, 0, 255, NULL,
  360. ECOLOR_GREEN_TEXT, ECOLOR_GREEN_LONGTEXT, false)
  361. add_integer_with_range(CFG_PREFIX "ecolor-blue", 192, 0, 255, NULL,
  362. ECOLOR_BLUE_TEXT, ECOLOR_BLUE_LONGTEXT, false)
  363. add_integer_with_range(CFG_PREFIX "efadesteps", 50, 1, 250, NULL,
  364. EFADESTEPS_TEXT, EFADESTEPS_LONGTEXT, false)
  365. set_section( N_("DMX options" ), 0 )
  366. add_integer_with_range(CFG_PREFIX "dmx-channels", 5, 1, 64, NULL,
  367. DMX_CHANNELS_TEXT, DMX_CHANNELS_LONGTEXT, false)
  368. add_string(CFG_PREFIX "dmx-chbase", "0,3,6,9,12",
  369. DMX_CHBASE_TEXT, DMX_CHBASE_LONGTEXT, false )
  370. set_section( N_("MoMoLight options" ), 0 )
  371. add_integer_with_range(CFG_PREFIX "momo-channels", 3, 3, 4, NULL,
  372. MOMO_CHANNELS_TEXT, MOMO_CHANNELS_LONGTEXT, false)
  373. /* 2,2,4 means 2 is the default value, 1 minimum amount,
  374. 4 maximum amount
  375. */
  376. set_section( N_("fnordlicht options" ), 0 )
  377. add_integer_with_range(CFG_PREFIX "fnordlicht-amount", 2, 1, 254, NULL,
  378. FNORDLICHT_AMOUNT_TEXT,
  379. FNORDLICHT_AMOUNT_LONGTEXT, false)
  380. /*
  381. instead of redefining the original AtmoLight zones with gradient
  382. bitmaps, we can now define the layout of the zones useing these
  383. parameters - the function with the gradient bitmaps would still
  384. work (but for most cases its no longer required)
  385. short description whats this means - f.e. the classic atmo would
  386. have this layout
  387. zones-top = 1 - zone 0
  388. zones-lr = 1 - zone 1 und zone 3
  389. zones-bottom = 1 - zone 2
  390. zone-summary = true - zone 4
  391. Z0
  392. ,------------,
  393. | |
  394. Z3| Z4 | Z1
  395. |____________|
  396. Z2
  397. the zone numbers will be counted clockwise starting at top / left
  398. if you want to split the light at the top, without having a bottom zone
  399. (which is my private config)
  400. zones-top = 2 - zone 0, zone 1
  401. zones-lr = 1 - zone 2 und zone 3
  402. zones-bottom = 0
  403. zone-summary = false
  404. Z0 Z1
  405. ,------------,
  406. | |
  407. Z3| | Z2
  408. |____________|
  409. */
  410. set_section( N_("Zone Layout for the build-in Atmo" ), 0 )
  411. add_integer_with_range(CFG_PREFIX "zones-top", 1, 0, 16, NULL,
  412. ZONE_TOP_TEXT, ZONE_TOP_LONGTEXT, false)
  413. add_integer_with_range(CFG_PREFIX "zones-bottom", 1, 0, 16, NULL,
  414. ZONE_BOTTOM_TEXT, ZONE_BOTTOM_LONGTEXT, false)
  415. add_integer_with_range(CFG_PREFIX "zones-lr", 1, 0, 16, NULL,
  416. ZONE_LR_TEXT, ZONE_LR_LONGTEXT, false)
  417. add_bool(CFG_PREFIX "zone-summary", false,
  418. ZONE_SUMMARY_TEXT, ZONE_SUMMARY_LONGTEXT, false)
  419. /*
  420. settings only for the buildin driver (if external driver app is used
  421. these parameters are ignored.)
  422. definition of parameters for the buildin filter ...
  423. */
  424. set_section( N_("Settings for the built-in Live Video Processor only" ), 0 )
  425. add_integer_with_range(CFG_PREFIX "edgeweightning", 3, 1, 30, NULL,
  426. EDGE_TEXT, EDGE_LONGTEXT, false)
  427. add_integer_with_range(CFG_PREFIX "brightness", 100, 50, 300, NULL,
  428. BRIGHTNESS_TEXT, BRIGHTNESS_LONGTEXT, false)
  429. add_integer_with_range(CFG_PREFIX "darknesslimit", 3, 0, 10, NULL,
  430. DARKNESS_TEXT, DARKNESS_LONGTEXT, false)
  431. add_integer_with_range(CFG_PREFIX "huewinsize", 3, 0, 5, NULL,
  432. HUEWINSIZE_TEXT, HUEWINSIZE_LONGTEXT, false)
  433. add_integer_with_range(CFG_PREFIX "satwinsize", 3, 0, 5, NULL,
  434. SATWINSIZE_TEXT, SATWINSIZE_LONGTEXT, false)
  435. add_integer(CFG_PREFIX "filtermode", (int)afmCombined,
  436. FILTERMODE_TEXT, FILTERMODE_LONGTEXT, false )
  437. change_integer_list(pi_filtermode_values, ppsz_filtermode_descriptions )
  438. add_integer_with_range(CFG_PREFIX "meanlength", 300, 300, 5000, NULL,
  439. MEANLENGTH_TEXT, MEANLENGTH_LONGTEXT, false)
  440. add_integer_with_range(CFG_PREFIX "meanthreshold", 40, 1, 100, NULL,
  441. MEANTHRESHOLD_TEXT, MEANTHRESHOLD_LONGTEXT, false)
  442. add_integer_with_range(CFG_PREFIX "percentnew", 50, 1, 100, NULL,
  443. MEANPERCENTNEW_TEXT, MEANPERCENTNEW_LONGTEXT, false)
  444. add_integer_with_range(CFG_PREFIX "framedelay", 18, 0, 200, NULL,
  445. FRAMEDELAY_TEXT, FRAMEDELAY_LONGTEXT, false)
  446. /*
  447. output channel reordering
  448. */
  449. set_section( N_("Change channel assignment (fixes wrong wiring)" ), 0 )
  450. add_integer( CFG_PREFIX "channel_0", 4,
  451. CHANNEL_0_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  452. change_integer_list( pi_zone_assignment_values,
  453. ppsz_zone_assignment_descriptions )
  454. add_integer( CFG_PREFIX "channel_1", 3,
  455. CHANNEL_1_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  456. change_integer_list( pi_zone_assignment_values,
  457. ppsz_zone_assignment_descriptions )
  458. add_integer( CFG_PREFIX "channel_2", 1,
  459. CHANNEL_2_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  460. change_integer_list( pi_zone_assignment_values,
  461. ppsz_zone_assignment_descriptions )
  462. add_integer( CFG_PREFIX "channel_3", 0,
  463. CHANNEL_3_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  464. change_integer_list( pi_zone_assignment_values,
  465. ppsz_zone_assignment_descriptions )
  466. add_integer( CFG_PREFIX "channel_4", 2,
  467. CHANNEL_4_ASSIGN_TEXT, CHANNELASSIGN_LONGTEXT, false )
  468. change_integer_list( pi_zone_assignment_values,
  469. ppsz_zone_assignment_descriptions )
  470. add_string(CFG_PREFIX "channels", "",
  471. CHANNELS_ASSIGN_TEXT, CHANNELS_ASSIGN_LONGTEXT, false )
  472. /*
  473. LED color white calibration
  474. */
  475. set_section( N_("Adjust the white light to your LED stripes" ), 0 )
  476. add_bool(CFG_PREFIX "whiteadj", true,
  477. USEWHITEADJ_TEXT, USEWHITEADJ_LONGTEXT, false)
  478. add_integer_with_range(CFG_PREFIX "white-red", 255, 0, 255, NULL,
  479. WHITE_RED_TEXT, WHITE_RED_LONGTEXT, false)
  480. add_integer_with_range(CFG_PREFIX "white-green", 255, 0, 255, NULL,
  481. WHITE_GREEN_TEXT, WHITE_GREEN_LONGTEXT, false)
  482. add_integer_with_range(CFG_PREFIX "white-blue", 255, 0, 255, NULL,
  483. WHITE_BLUE_TEXT, WHITE_BLUE_LONGTEXT, false)
  484. /* end of definition of parameter for the buildin filter ... part 1 */
  485. /*
  486. only for buildin (external has own definition) per default the calucation
  487. used linear gradients for assigning a priority to the pixel - depending
  488. how near they are to the border ...for changing this you can create 64x48
  489. Pixel BMP files - which contain your own grayscale... (you can produce funny
  490. effects with this...) the images MUST not compressed, should have 24-bit per
  491. pixel, or a simple 256 color grayscale palette
  492. */
  493. set_section( N_("Change gradients" ), 0 )
  494. add_loadfile(CFG_PREFIX "gradient_zone_0", NULL,
  495. ZONE_0_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  496. add_loadfile(CFG_PREFIX "gradient_zone_1", NULL,
  497. ZONE_1_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  498. add_loadfile(CFG_PREFIX "gradient_zone_2", NULL,
  499. ZONE_2_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  500. add_loadfile(CFG_PREFIX "gradient_zone_3", NULL,
  501. ZONE_3_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  502. add_loadfile(CFG_PREFIX "gradient_zone_4", NULL,
  503. ZONE_4_GRADIENT_TEXT, ZONE_X_GRADIENT_LONG_TEXT, true )
  504. add_directory(CFG_PREFIX "gradient_path", NULL,
  505. GRADIENT_PATH_TEXT, GRADIENT_PATH_LONGTEXT, false )
  506. #if defined(__ATMO_DEBUG__)
  507. add_bool(CFG_PREFIX "saveframes", false,
  508. SAVEFRAMES_TEXT, SAVEFRAMES_LONGTEXT, false)
  509. add_string(CFG_PREFIX "framepath", "",
  510. FRAMEPATH_TEXT, FRAMEPATH_LONGTEXT, false )
  511. #endif
  512. /*
  513. may be later if computers gets more power ;-) than now we increase
  514. the samplesize from which we do the stats for output color calculation
  515. */
  516. add_integer_with_range(CFG_PREFIX "width", 64, 64, 512, NULL,
  517. WIDTH_TEXT, WIDTH_LONGTEXT, true)
  518. add_integer_with_range(CFG_PREFIX "height", 48, 48, 384, NULL,
  519. HEIGHT_TEXT, HEIGHT_LONGTEXT, true)
  520. add_bool(CFG_PREFIX "showdots", false,
  521. SHOW_DOTS_TEXT, SHOW_DOTS_LONGTEXT, false)
  522. add_shortcut( "atmo" )
  523. set_callbacks( CreateFilter, DestroyFilter )
  524. vlc_module_end ()
  525. static const char *const ppsz_filter_options[] = {
  526. "device",
  527. "serialdev",
  528. "edgeweightning",
  529. "brightness",
  530. "darknesslimit",
  531. "huewinsize",
  532. "satwinsize",
  533. "filtermode",
  534. "meanlength",
  535. "meanthreshold",
  536. "percentnew",
  537. "framedelay",
  538. "zones-top",
  539. "zones-bottom",
  540. "zones-lr",
  541. "zone-summary",
  542. "channel_0",
  543. "channel_1",
  544. "channel_2",
  545. "channel_3",
  546. "channel_4",
  547. "channels",
  548. "whiteadj",
  549. "white-red",
  550. "white-green",
  551. "white-blue",
  552. "usepausecolor",
  553. "pcolor-red",
  554. "pcolor-green",
  555. "pcolor-blue",
  556. "fadesteps",
  557. "ecolor-red",
  558. "ecolor-green",
  559. "ecolor-blue",
  560. "efadesteps",
  561. "dmx-channels",
  562. "dmx-chbase",
  563. "momo-channels",
  564. "fnordlicht-amount",
  565. #if defined(WIN32 )
  566. "atmowinexe",
  567. #endif
  568. #if defined(__ATMO_DEBUG__)
  569. "saveframes" ,
  570. "framepath",
  571. #endif
  572. "width",
  573. "height",
  574. "showdots",
  575. "gradient_zone_0",
  576. "gradient_zone_1",
  577. "gradient_zone_2",
  578. "gradient_zone_3",
  579. "gradient_zone_4",
  580. "gradient_path",
  581. NULL
  582. };
  583. /*****************************************************************************
  584. * fadethread_t: Color Fading Thread
  585. *****************************************************************************
  586. * changes slowly the color of the output if videostream gets paused...
  587. *****************************************************************************
  588. */
  589. typedef struct
  590. {
  591. VLC_COMMON_MEMBERS
  592. filter_t *p_filter;
  593. /* tell the thread which color should be the target of fading */
  594. uint8_t ui_red;
  595. uint8_t ui_green;
  596. uint8_t ui_blue;
  597. /* how many steps should happen until this */
  598. int i_steps;
  599. } fadethread_t;
  600. static void *FadeToColorThread(vlc_object_t *);
  601. /*****************************************************************************
  602. * filter_sys_t: AtmoLight filter method descriptor
  603. *****************************************************************************
  604. * It describes the AtmoLight specific properties of an video filter.
  605. *****************************************************************************/
  606. struct filter_sys_t
  607. {
  608. /*
  609. special for the access of the p_fadethread member all other members
  610. need no special protection so far!
  611. */
  612. vlc_mutex_t filter_lock;
  613. bool b_enabled;
  614. int32_t i_AtmoOldEffect;
  615. bool b_pause_live;
  616. bool b_show_dots;
  617. int32_t i_device_type;
  618. int32_t i_atmo_width;
  619. int32_t i_atmo_height;
  620. /* used to disable fadeout if less than 50 frames are processed
  621. used to avoid long time waiting when switch quickly between
  622. deinterlaceing modes, where the output filter chains is rebuild
  623. on each switch
  624. */
  625. int32_t i_frames_processed;
  626. #if defined(__ATMO_DEBUG__)
  627. bool b_saveframes;
  628. uint32_t ui_frame_counter;
  629. char sz_framepath[MAX_PATH];
  630. #endif
  631. /* light color durring movie pause ... */
  632. bool b_usepausecolor;
  633. uint8_t ui_pausecolor_red;
  634. uint8_t ui_pausecolor_green;
  635. uint8_t ui_pausecolor_blue;
  636. int i_fadesteps;
  637. /* light color on movie finish ... */
  638. uint8_t ui_endcolor_red;
  639. uint8_t ui_endcolor_green;
  640. uint8_t ui_endcolor_blue;
  641. int i_endfadesteps;
  642. fadethread_t *p_fadethread;
  643. /* Variables for buildin driver only... */
  644. /* is only present and initialized if the internal driver is used*/
  645. CAtmoConfig *p_atmo_config;
  646. /* storage for temporal settings "volatile" */
  647. CAtmoDynData *p_atmo_dyndata;
  648. /* initialized for buildin driver with AtmoCreateTransferBuffers */
  649. BITMAPINFOHEADER mini_image_format;
  650. /* is only use buildin driver! */
  651. uint8_t *p_atmo_transfer_buffer;
  652. /* end buildin driver */
  653. /*
  654. contains the real output size of the video calculated on
  655. change event of the variable "crop" from vout
  656. */
  657. int32_t i_crop_x_offset;
  658. int32_t i_crop_y_offset;
  659. int32_t i_crop_width;
  660. int32_t i_crop_height;
  661. void (*pf_extract_mini_image) (filter_sys_t *p_sys,
  662. picture_t *p_inpic,
  663. uint8_t *p_transfer_dest);
  664. #if defined( WIN32 )
  665. /* External Library as wrapper arround COM Stuff */
  666. HINSTANCE h_AtmoCtrl;
  667. int32_t (*pf_ctrl_atmo_initialize) (void);
  668. void (*pf_ctrl_atmo_finalize) (int32_t what);
  669. int32_t (*pf_ctrl_atmo_switch_effect) (int32_t);
  670. int32_t (*pf_ctrl_atmo_set_live_source) (int32_t);
  671. void (*pf_ctrl_atmo_create_transfer_buffers) (int32_t, int32_t,
  672. int32_t , int32_t);
  673. uint8_t* (*pf_ctrl_atmo_lock_transfer_buffer) (void);
  674. void (*pf_ctrl_atmo_send_pixel_data) (void);
  675. void (*pf_ctrl_atmo_get_image_size)(int32_t *,int32_t *);
  676. #endif
  677. };
  678. /*
  679. initialize previously configured Atmo Light environment
  680. - if internal is enabled try to access the device on the serial port
  681. - if not internal is enabled and we are on win32 try to initialize
  682. the previously loaded DLL ...
  683. Return Values may be: -1 (failed for some reason - filter will be disabled)
  684. 1 Ok. lets rock
  685. */
  686. static int32_t AtmoInitialize(filter_t *p_filter, bool b_for_thread)
  687. {
  688. filter_sys_t *p_sys = p_filter->p_sys;
  689. if(p_sys->p_atmo_config)
  690. {
  691. if(b_for_thread == false)
  692. {
  693. /* open com port */
  694. /* setup Output Threads ... */
  695. msg_Dbg( p_filter, "open atmo device...");
  696. if(CAtmoTools::RecreateConnection(p_sys->p_atmo_dyndata)
  697. == ATMO_TRUE)
  698. {
  699. return 1;
  700. } else {
  701. msg_Err( p_filter,"failed to open atmo device, "\
  702. "some other software/driver may use it?");
  703. }
  704. }
  705. #if defined(WIN32)
  706. } else if(p_sys->pf_ctrl_atmo_initialize)
  707. {
  708. /* on win32 with active ctrl dll */
  709. return p_sys->pf_ctrl_atmo_initialize();
  710. #endif
  711. }
  712. return -1;
  713. }
  714. /*
  715. prepare the shutdown of the effect threads,
  716. for build in filter - close the serialport after finishing the threads...
  717. cleanup possible loaded DLL...
  718. */
  719. static void AtmoFinalize(filter_t *p_filter, int32_t what)
  720. {
  721. filter_sys_t *p_sys = p_filter->p_sys;
  722. if(p_sys->p_atmo_config)
  723. {
  724. if(what == 1)
  725. {
  726. CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  727. if(p_atmo_dyndata)
  728. {
  729. p_atmo_dyndata->LockCriticalSection();
  730. CAtmoInput *p_input = p_atmo_dyndata->getLiveInput();
  731. p_atmo_dyndata->setLiveInput( NULL );
  732. if(p_input != NULL)
  733. {
  734. p_input->Terminate();
  735. delete p_input;
  736. msg_Dbg( p_filter, "input thread died peacefully");
  737. }
  738. CThread *p_effect_thread = p_atmo_dyndata->getEffectThread();
  739. p_atmo_dyndata->setEffectThread(NULL);
  740. if(p_effect_thread != NULL)
  741. {
  742. /*
  743. forced the thread to die...
  744. and wait for termination of the thread
  745. */
  746. p_effect_thread->Terminate();
  747. delete p_effect_thread;
  748. msg_Dbg( p_filter, "effect thread died peacefully");
  749. }
  750. CAtmoPacketQueue *p_queue =
  751. p_atmo_dyndata->getLivePacketQueue();
  752. p_atmo_dyndata->setLivePacketQueue( NULL );
  753. if(p_queue != NULL)
  754. {
  755. delete p_queue;
  756. msg_Dbg( p_filter, "packetqueue removed");
  757. }
  758. /*
  759. close serial port if it is open (all OS specific is inside
  760. CAtmoSerialConnection implemented / defined)
  761. */
  762. CAtmoConnection *p_atmo_connection =
  763. p_atmo_dyndata->getAtmoConnection();
  764. p_atmo_dyndata->setAtmoConnection(NULL);
  765. if(p_atmo_connection) {
  766. p_atmo_connection->CloseConnection();
  767. delete p_atmo_connection;
  768. }
  769. p_atmo_dyndata->UnLockCriticalSection();
  770. }
  771. }
  772. #if defined(WIN32)
  773. } else if(p_sys->pf_ctrl_atmo_finalize)
  774. {
  775. /* on win32 with active ctrl dll */
  776. p_sys->pf_ctrl_atmo_finalize(what);
  777. #endif
  778. }
  779. }
  780. /*
  781. switch the current light effect to LiveView
  782. */
  783. static int32_t AtmoSwitchEffect(filter_t *p_filter, int32_t newMode)
  784. {
  785. filter_sys_t *p_sys = p_filter->p_sys;
  786. msg_Dbg( p_filter, "AtmoSwitchEffect %d", newMode );
  787. if(p_sys->p_atmo_config)
  788. {
  789. return CAtmoTools::SwitchEffect(p_sys->p_atmo_dyndata, emLivePicture);
  790. #if defined(WIN32)
  791. } else if(p_sys->pf_ctrl_atmo_switch_effect)
  792. {
  793. /* on win32 with active ctrl dll */
  794. return p_sys->pf_ctrl_atmo_switch_effect( newMode );
  795. #endif
  796. }
  797. return emDisabled;
  798. }
  799. /*
  800. set the current live picture source, does only something on win32,
  801. with the external libraries - if the buildin effects are used nothing
  802. happens...
  803. */
  804. static int32_t AtmoSetLiveSource(filter_t *p_filter, int32_t newSource)
  805. {
  806. filter_sys_t *p_sys = p_filter->p_sys;
  807. msg_Dbg( p_filter, "AtmoSetLiveSource %d", newSource );
  808. if(p_sys->p_atmo_config)
  809. {
  810. /*
  811. buildin driver
  812. doesnt know different sources so this
  813. function call would just do nothing special
  814. in this case
  815. */
  816. #if defined(WIN32)
  817. } else if(p_sys->pf_ctrl_atmo_set_live_source)
  818. {
  819. /* on win32 with active ctrl dll */
  820. return p_sys->pf_ctrl_atmo_set_live_source(newSource);
  821. #endif
  822. }
  823. return lvsGDI;
  824. }
  825. /*
  826. setup the pixel transferbuffers which is used to transfer pixeldata from
  827. the filter to the effect thread, and possible accross the process
  828. boundaries on win32, with the external DLL
  829. */
  830. static void AtmoCreateTransferBuffers(filter_t *p_filter,
  831. int32_t FourCC,
  832. int32_t bytePerPixel,
  833. int32_t width,
  834. int32_t height)
  835. {
  836. filter_sys_t *p_sys = p_filter->p_sys;
  837. if(p_sys->p_atmo_config)
  838. {
  839. /*
  840. we need a buffer where the image is stored (only for transfer
  841. to the processing thread)
  842. */
  843. free( p_sys->p_atmo_transfer_buffer );
  844. p_sys->p_atmo_transfer_buffer = (uint8_t *)malloc(bytePerPixel *
  845. width * height);
  846. memset(&p_sys->mini_image_format,0,sizeof(BITMAPINFOHEADER));
  847. p_sys->mini_image_format.biSize = sizeof(BITMAPINFOHEADER);
  848. p_sys->mini_image_format.biWidth = width;
  849. p_sys->mini_image_format.biHeight = height;
  850. p_sys->mini_image_format.biBitCount = bytePerPixel*8;
  851. p_sys->mini_image_format.biCompression = FourCC;
  852. #if defined(WIN32)
  853. } else if(p_sys->pf_ctrl_atmo_create_transfer_buffers)
  854. {
  855. /* on win32 with active ctrl dll */
  856. p_sys->pf_ctrl_atmo_create_transfer_buffers(FourCC,
  857. bytePerPixel,
  858. width,
  859. height);
  860. #endif
  861. }
  862. }
  863. /*
  864. acquire the transfer buffer pointer the buildin version only
  865. returns the pointer to the allocated buffer ... the
  866. external version on win32 has to do some COM stuff to lock the
  867. Variant Byte array which is behind the buffer
  868. */
  869. static uint8_t* AtmoLockTransferBuffer(filter_t *p_filter)
  870. {
  871. filter_sys_t *p_sys = p_filter->p_sys;
  872. if(p_sys->p_atmo_config)
  873. {
  874. return p_sys->p_atmo_transfer_buffer;
  875. #if defined(WIN32)
  876. } else if(p_sys->pf_ctrl_atmo_lock_transfer_buffer)
  877. {
  878. /* on win32 with active ctrl dll */
  879. return p_sys->pf_ctrl_atmo_lock_transfer_buffer();
  880. #endif
  881. }
  882. return NULL;
  883. }
  884. /*
  885. send the content of current pixel buffer got with AtmoLockTransferBuffer
  886. to the processing threads
  887. - build in version - will forward the data to AtmoExternalCaptureInput Thread
  888. - win32 external - will do the same, but across the process boundaries via
  889. COM to the AtmoWinA.exe Process
  890. */
  891. static void AtmoSendPixelData(filter_t *p_filter)
  892. {
  893. filter_sys_t *p_sys = p_filter->p_sys;
  894. if(p_sys->p_atmo_config && p_sys->p_atmo_transfer_buffer)
  895. {
  896. CAtmoDynData *p_atmo_dyndata = p_sys->p_atmo_dyndata;
  897. if(p_atmo_dyndata &&
  898. (p_atmo_dyndata->getLivePictureSource() == lpsExtern))
  899. {
  900. /*
  901. the cast will go Ok because we are inside videolan there is only
  902. this kind of effect thread implemented!
  903. */
  904. CAtmoExternalCaptureInput *p_atmo_external_capture_input_thread =
  905. (CAtmoExternalCaptureInput *)p_atmo_dyndata->getLiveInput();
  906. if(p_atmo_external_capture_input_thread)
  907. {
  908. /*
  909. the same as above inside videolan only this single kind of
  910. input exists so we can cast without further tests!
  911. this call will do a 1:1 copy of this buffer, and wakeup
  912. the thread from normal sleeping
  913. */
  914. p_atmo_external_capture_input_thread->
  915. DeliverNewSourceDataPaket(&p_sys->mini_image_format,
  916. p_sys->p_atmo_transfer_buffer);
  917. }
  918. }
  919. #if defined(WIN32)
  920. } else if(p_sys->pf_ctrl_atmo_send_pixel_data)
  921. {
  922. /* on win32 with active ctrl dll */
  923. p_sys->pf_ctrl_atmo_send_pixel_data();
  924. #endif
  925. } else
  926. {
  927. msg_Warn( p_filter, "AtmoSendPixelData no method");
  928. }
  929. }
  930. /*
  931. Shutdown AtmoLight finally - is call from DestroyFilter
  932. does the cleanup restores the effectmode on the external Software
  933. (only win32) and possible setup the final light ...
  934. */
  935. static void Atmo_Shutdown(filter_t *p_filter)
  936. {
  937. filter_sys_t *p_sys = p_filter->p_sys;
  938. if(p_sys->b_enabled == true)
  939. {
  940. msg_Dbg( p_filter, "shut down atmo!");
  941. /*
  942. if there is a still running show pause color thread kill him!
  943. */
  944. CheckAndStopFadeThread(p_filter);
  945. // perpare spawn fadeing thread
  946. vlc_mutex_lock( &p_sys->filter_lock );
  947. /*
  948. fade to end color (in case of external AtmoWin Software
  949. assume that the static color will equal to this
  950. one to get a soft change and no flash!
  951. */
  952. p_sys->b_pause_live = true;
  953. p_sys->p_fadethread = (fadethread_t *)vlc_object_create( p_filter,
  954. sizeof(fadethread_t) );
  955. p_sys->p_fadethread->p_filter = p_filter;
  956. p_sys->p_fadethread->ui_red = p_sys->ui_endcolor_red;
  957. p_sys->p_fadethread->ui_green = p_sys->ui_endcolor_green;
  958. p_sys->p_fadethread->ui_blue = p_sys->ui_endcolor_blue;
  959. if(p_sys->i_frames_processed < 50)
  960. p_sys->p_fadethread->i_steps = 1;
  961. else
  962. p_sys->p_fadethread->i_steps = p_sys->i_endfadesteps;
  963. if( vlc_thread_create( p_sys->p_fadethread,
  964. "AtmoLight fadeing",
  965. FadeToColorThread,
  966. VLC_THREAD_PRIORITY_LOW ) )
  967. {
  968. msg_Err( p_filter, "cannot create FadeToColorThread" );
  969. vlc_object_release( p_sys->p_fadethread );
  970. p_sys->p_fadethread = NULL;
  971. vlc_mutex_unlock( &p_sys->filter_lock );
  972. } else {
  973. vlc_mutex_unlock( &p_sys->filter_lock );
  974. /* wait for the thread... */
  975. vlc_thread_join(p_sys->p_fadethread);
  976. vlc_object_release(p_sys->p_fadethread);
  977. p_sys->p_fadethread = NULL;
  978. }
  979. /*
  980. the following happens only useing the
  981. external AtmoWin Device Software
  982. */
  983. if( !p_sys->p_atmo_config )
  984. {
  985. if(p_sys->i_AtmoOldEffect != emLivePicture)
  986. AtmoSwitchEffect( p_filter, p_sys->i_AtmoOldEffect);
  987. else
  988. AtmoSetLiveSource( p_filter, lvsGDI );
  989. }
  990. /* close device connection etc. */
  991. AtmoFinalize(p_filter, 1);
  992. /* disable filter method .. */
  993. p_sys->b_enabled = false;
  994. }
  995. }
  996. /*
  997. depending on mode setup imagesize to 64x48(classic), or defined
  998. resolution of external atmowin.exe on windows
  999. */
  1000. static void Atmo_SetupImageSize(filter_t *p_filter)
  1001. {
  1002. filter_sys_t *p_sys = p_filter->p_sys;
  1003. /*
  1004. size of extracted image by default 64x48 (other imagesizes are
  1005. currently ignored by AtmoWin)
  1006. */
  1007. p_sys->i_atmo_width = var_CreateGetIntegerCommand( p_filter,
  1008. CFG_PREFIX "width");
  1009. p_sys->i_atmo_height = var_CreateGetIntegerCommand( p_filter,
  1010. CFG_PREFIX "height");
  1011. if(p_sys->p_atmo_config)
  1012. {
  1013. #if defined(WIN32)
  1014. } else if(p_sys->pf_ctrl_atmo_get_image_size)
  1015. {
  1016. /* on win32 with active ctrl dll */
  1017. p_sys->pf_ctrl_atmo_get_image_size( &p_sys->i_atmo_width,
  1018. &p_sys->i_atmo_height );
  1019. #endif
  1020. }
  1021. msg_Dbg(p_filter,"sample image size %d * %d pixels", p_sys->i_atmo_width,
  1022. p_sys->i_atmo_height);
  1023. }
  1024. /*
  1025. initialize the zone and channel mapping for the buildin atmolight adapter
  1026. */
  1027. static void Atmo_SetupBuildZones(filter_t *p_filter)
  1028. {
  1029. filter_sys_t *p_sys = p_filter->p_sys;
  1030. p_sys->p_atmo_dyndata->LockCriticalSection();
  1031. CAtmoConfig *p_atmo_config = p_sys->p_atmo_config;
  1032. CAtmoChannelAssignment *p_channel_assignment =
  1033. p_atmo_config->getChannelAssignment(0);
  1034. // channel 0 - zone 4
  1035. p_channel_assignment->setZoneIndex( 0, var_CreateGetIntegerCommand(
  1036. p_filter, CFG_PREFIX "channel_0")
  1037. );
  1038. // channel 1 - zone 3
  1039. p_channel_assignment->setZoneIndex( 1, var_CreateGetIntegerCommand(
  1040. p_filter, CFG_PREFIX "channel_1")
  1041. );
  1042. // channel 2 - zone 1
  1043. p_channel_assignment->setZoneIndex( 2, var_CreateGetIntegerCommand(
  1044. p_filter, CFG_PREFIX "channel_2")
  1045. );
  1046. // channel 3 - zone 0
  1047. p_channel_assignment->setZoneIndex( 3, var_CreateGetIntegerCommand(
  1048. p_filter, CFG_PREFIX "channel_3")
  1049. );
  1050. // channel 4 - zone 2
  1051. p_channel_assignment->setZoneIndex( 4, var_CreateGetIntegerCommand(
  1052. p_filter, CFG_PREFIX "channel_4")
  1053. );
  1054. char *psz_channels = var_CreateGetStringCommand(
  1055. p_filter,
  1056. CFG_PREFIX "channels"
  1057. );
  1058. if( !EMPTY_STR(psz_channels) )
  1059. {
  1060. msg_Dbg( p_filter, "deal with new zone mapping %s", psz_channels );
  1061. int channel = 0;
  1062. char *psz_temp = psz_channels;
  1063. char *psz_start = psz_temp;
  1064. while( *psz_temp )
  1065. {
  1066. if(*psz_temp == ',' || *psz_temp == ';')
  1067. {
  1068. *psz_temp = 0;
  1069. if(*psz_start)
  1070. {
  1071. int zone = atoi( psz_start );
  1072. if( zone < -1 ||
  1073. zone >= p_channel_assignment->getSize()) {
  1074. msg_Warn( p_filter, "Zone %d out of range -1..%d",
  1075. zone, p_channel_assignment->getSize()-1 );
  1076. } else {
  1077. p_channel_assignment->setZoneIndex( channel, zone );
  1078. channel++;
  1079. }
  1080. }
  1081. psz_start = psz_temp;
  1082. psz_start++;
  1083. }
  1084. psz_temp++;
  1085. }
  1086. /*
  1087. process the rest of the string
  1088. */
  1089. if( *psz_start && !*psz_temp )
  1090. {
  1091. int zone = atoi( psz_start );
  1092. if( zone < -1 ||
  1093. zone >= p_channel_assignment->getSize()) {
  1094. msg_Warn( p_filter, "Zone %d out of range -1..%d",
  1095. zone, p_channel_assignment->getSize()-1 );
  1096. } else {
  1097. p_channel_assignment->setZoneIndex( channel, zone );
  1098. }
  1099. }
  1100. }
  1101. free( psz_channels );
  1102. for(int i=0;i< p_channel_assignment->getSize() ;i++)
  1103. msg_Info( p_filter, "map zone %d to hardware channel %d",
  1104. p_channel_assignment->getZoneIndex( i ),
  1105. i
  1106. );
  1107. p_sys->p_atmo_dyndata->getAtmoConnection()
  1108. ->SetChannelAssignment( p_channel_assignment );
  1109. /*
  1110. calculate the default gradients for each zone!
  1111. depending on the zone layout set before, this now
  1112. supports also multiple gradients on each side
  1113. (older versions could do this only with external
  1114. gradient bitmaps)
  1115. */
  1116. p_sys->p_atmo_dyndata->CalculateDefaultZones();
  1117. /*
  1118. first try to load the old style defined gradient bitmaps
  1119. this could only be done for the first five zones
  1120. - should be deprecated -
  1121. */
  1122. CAtmoZoneDefinition *p_zone;
  1123. char psz_gradient_var_name[30];
  1124. char *psz_gradient_file;
  1125. for(int i=0;i<CLASSIC_ATMO_NUM_ZONES;i++)
  1126. {
  1127. sprintf(psz_gradient_var_name, CFG_PREFIX "gradient_zone_%d", i);
  1128. psz_gradient_file = var_CreateGetStringCommand(
  1129. p_filter,
  1130. psz_gradient_var_name
  1131. );
  1132. if( !EMPTY_STR(psz_gradient_file) )
  1133. {
  1134. msg_Dbg( p_filter, "loading gradientfile %s for "\
  1135. "zone %d", psz_gradient_file, i);
  1136. p_zone = p_atmo_config->getZoneDefinition(i);
  1137. if( p_zone )
  1138. {
  1139. int i_res = p_zone->LoadGradientFromBitmap(psz_gradient_file);
  1140. if(i_res != ATMO_LOAD_GRADIENT_OK)
  1141. {
  1142. msg_Err( p_filter,"failed to load gradient '%s' with "\
  1143. "error %d",psz_gradient_file,i_res);
  1144. }
  1145. }
  1146. }
  1147. free( psz_gradient_file );
  1148. }
  1149. /*
  1150. the new approach try to load a gradient bitmap for each zone
  1151. from a previously defined folder containing
  1152. zone_0.bmp
  1153. zone_1.bmp
  1154. zone_2.bmp etc.
  1155. */
  1156. char *psz_gradient_path = var_CreateGetStringCommand(
  1157. p_filter,
  1158. CFG_PREFIX "gradient_path"
  1159. );
  1160. if( EMPTY_STR(psz_gradient_path) )
  1161. {
  1162. char *psz_file_name = (char *)malloc( strlen(psz_gradient_path) + 16 );
  1163. assert( psz_file_name );
  1164. for(int i=0; i < p_atmo_config->getZoneCount(); i++ )
  1165. {
  1166. p_zone = p_atmo_config->getZoneDefinition(i);
  1167. if( p_zone )
  1168. {
  1169. sprintf(psz_file_name, "%s%szone_%d.bmp",
  1170. psz_gradient_path, DIR_SEP, i );
  1171. int i_res = p_zone->LoadGradientFromBitmap( psz_file_name );
  1172. if( i_res == ATMO_LOAD_GRADIENT_OK )
  1173. {
  1174. msg_Dbg( p_filter, "loaded gradientfile %s for "\
  1175. "zone %d", psz_file_name, i);
  1176. }
  1177. if( (i_res != ATMO_LOAD_GRADIENT_OK) &&
  1178. (i_res != ATMO_LOAD_GRADIENT_FILENOTFOND) )
  1179. {
  1180. msg_Err( p_filter,"failed to load gradient '%s' with "\
  1181. "error %d",psz_file_name,i_res);
  1182. }
  1183. }
  1184. }
  1185. free( psz_file_name );
  1186. }
  1187. free( psz_gradient_path );
  1188. p_sys->p_atmo_dyndata->UnLockCriticalSection();
  1189. }
  1190. static void Atmo_SetupConfig(filter_t *p_filter, CAtmoConfig *p_atmo_config)
  1191. {
  1192. /*
  1193. figuring out the device ports (com-ports, ttys)
  1194. */
  1195. char *psz_serialdev = var_CreateGetStringCommand( p_filter,
  1196. CFG_PREFIX "serialdev" );
  1197. char *psz_temp = psz_serialdev;
  1198. if( !EMPTY_STR(psz_serialdev) )
  1199. {
  1200. char *psz_token;
  1201. int i_port = 0;
  1202. int i;
  1203. int j;
  1204. msg_Dbg( p_filter, "use port(s) %s",psz_serialdev);
  1205. /*
  1206. psz_serialdev - may contain up to 4 COM ports for the quattro device
  1207. the quattro device is just hack of useing 4 classic devices as one
  1208. logical device - thanks that usb-com-ports exists :)
  1209. as Seperator I defined , or ; with the hope that these
  1210. characters are never part of a device name
  1211. */
  1212. while( (psz_token = strsep(&psz_temp, ",;")) != NULL && i_port < 4 )
  1213. {
  1214. /*
  1215. psz_token may contain spaces we have to trim away
  1216. */
  1217. i = 0;
  1218. j = 0;
  1219. /*
  1220. find first none space in string
  1221. */
  1222. while( psz_token[i] == 32 ) i++;
  1223. /*
  1224. contains string only spaces or is empty? skip it
  1225. */
  1226. if( !psz_token[i] )
  1227. continue;
  1228. /*
  1229. trim
  1230. */
  1231. while( psz_token[i] && psz_token[i] != 32 )
  1232. psz_token[ j++ ] = psz_token[ i++ ];
  1233. psz_token[j++] = 0;
  1234. msg_Dbg( p_filter, "Serial Device [%d]: %s", i_port, psz_token );
  1235. p_atmo_config->setSerialDevice( i_port, psz_token );
  1236. i_port++;
  1237. }
  1238. }
  1239. else
  1240. {
  1241. msg_Err(p_filter,"no serial devicename(s) set");
  1242. }
  1243. free( psz_serialdev );
  1244. /*
  1245. configuration of light source layout arround the display
  1246. */
  1247. p_atmo_config->setZonesTopCount(
  1248. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "zones-top")
  1249. );
  1250. p_atmo_config->setZonesBottomCount(
  1251. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "zones-bottom")
  1252. );
  1253. p_atmo_config->setZonesLRCount(
  1254. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "zones-lr")
  1255. );
  1256. p_atmo_config->setZoneSummary(
  1257. var_CreateGetBoolCommand( p_filter, CFG_PREFIX "zone-summary")
  1258. );
  1259. p_atmo_config->setLiveViewFilterMode(
  1260. (AtmoFilterMode)var_CreateGetIntegerCommand( p_filter,
  1261. CFG_PREFIX "filtermode")
  1262. );
  1263. p_atmo_config->setLiveViewFilter_PercentNew(
  1264. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "percentnew")
  1265. );
  1266. p_atmo_config->setLiveViewFilter_MeanLength(
  1267. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "meanlength")
  1268. );
  1269. p_atmo_config->setLiveViewFilter_MeanThreshold(
  1270. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "meanthreshold")
  1271. );
  1272. p_atmo_config->setLiveView_EdgeWeighting(
  1273. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "edgeweightning")
  1274. );
  1275. p_atmo_config->setLiveView_BrightCorrect(
  1276. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "brightness")
  1277. );
  1278. p_atmo_config->setLiveView_DarknessLimit(
  1279. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "darknesslimit")
  1280. );
  1281. p_atmo_config->setLiveView_HueWinSize(
  1282. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "huewinsize")
  1283. );
  1284. p_atmo_config->setLiveView_SatWinSize(
  1285. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "satwinsize")
  1286. );
  1287. /* currently not required inside vlc */
  1288. p_atmo_config->setLiveView_WidescreenMode( 0 );
  1289. p_atmo_config->setLiveView_FrameDelay(
  1290. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "framedelay")
  1291. );
  1292. p_atmo_config->setUseSoftwareWhiteAdj(
  1293. var_CreateGetBoolCommand( p_filter, CFG_PREFIX "whiteadj")
  1294. );
  1295. p_atmo_config->setWhiteAdjustment_Red(
  1296. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-red")
  1297. );
  1298. p_atmo_config->setWhiteAdjustment_Green(
  1299. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-green")
  1300. );
  1301. p_atmo_config->setWhiteAdjustment_Blue(
  1302. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "white-blue")
  1303. );
  1304. /*
  1305. settings for DMX device only
  1306. */
  1307. p_atmo_config->setDMX_RGB_Channels(
  1308. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "dmx-channels")
  1309. );
  1310. char *psz_chbase = var_CreateGetStringCommand( p_filter,
  1311. CFG_PREFIX "dmx-chbase" );
  1312. if( !EMPTY_STR(psz_chbase) )
  1313. p_atmo_config->setDMX_BaseChannels( psz_chbase );
  1314. free( psz_chbase );
  1315. /*
  1316. momolight options
  1317. */
  1318. p_atmo_config->setMoMo_Channels(
  1319. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "momo-channels")
  1320. );
  1321. /*
  1322. fnordlicht options
  1323. */
  1324. p_atmo_config->setFnordlicht_Amount(
  1325. var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "fnordlicht-amount")
  1326. );
  1327. }
  1328. /*
  1329. initialize the filter_sys_t structure with the data from the settings
  1330. variables - if the external filter on win32 is enabled try loading the DLL,
  1331. if this fails fallback to the buildin software
  1332. */
  1333. static void Atmo_SetupParameters(filter_t *p_filter)
  1334. {
  1335. char *psz_path;
  1336. filter_sys_t *p_sys = p_filter->p_sys;
  1337. /* default filter disabled until DLL loaded and Init Success!*/
  1338. p_sys->b_enabled = false;
  1339. /* setup default mini image size (may be later a user option) */
  1340. p_sys->i_atmo_width = 64;
  1341. p_sys->i_atmo_height = 48;
  1342. p_sys->i_device_type = var_CreateGetIntegerCommand( p_filter,
  1343. CFG_PREFIX "device");
  1344. /*
  1345. i_device_type
  1346. 0 => use AtmoWin Software (only win32)
  1347. 1 => use AtmoClassicConnection (direct)
  1348. 2 => use AtmoMultiConnection (direct up to four serial ports required)
  1349. 3 => use AtmoDmxConnection (simple serial DMX Device up to 255 channels)
  1350. */
  1351. #if defined(WIN32)
  1352. /*
  1353. only on WIN32 the user has the choice between
  1354. internal driver and external
  1355. */
  1356. if(p_sys->i_device_type == 0) {
  1357. /* Load the Com Wrapper Library (source available) */
  1358. p_sys->h_AtmoCtrl = LoadLibraryA("AtmoCtrlLib.dll");
  1359. if(p_sys->h_AtmoCtrl == NULL)
  1360. {
  1361. /*
  1362. be clever if the location of atmowina.exe is set
  1363. try to load the dll from the same folder :-)
  1364. */
  1365. char *psz_path = var_CreateGetStringCommand( p_filter,
  1366. CFG_PREFIX "atmowinexe" );
  1367. if( !EMPTY_STR(psz_path) )
  1368. {
  1369. char *psz_bs = strrchr( psz_path , '\\');
  1370. if( psz_bs )
  1371. {
  1372. *psz_bs = 0;
  1373. /*
  1374. now format a new dll filename with complete path
  1375. */
  1376. char *psz_dllname = NULL;
  1377. asprintf( &psz_dllname, "%s\\AtmoCtrlLib.dll", psz_path );
  1378. if( psz_dllname )
  1379. {
  1380. msg_Dbg( p_filter, "Try Loading '%s'", psz_dllname );
  1381. p_sys->h_AtmoCtrl = LoadLibraryA( psz_dllname );
  1382. }
  1383. free( psz_dllname );
  1384. }
  1385. }
  1386. free( psz_path );
  1387. }
  1388. if(p_sys->h_AtmoCtrl != NULL)
  1389. {
  1390. msg_Dbg( p_filter, "Load Library ok!");
  1391. /* importing all required functions I hope*/
  1392. p_sys->pf_ctrl_atmo_initialize =
  1393. (int32_t (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,
  1394. "AtmoInitialize");
  1395. if(!p_sys->pf_ctrl_atmo_initialize)
  1396. msg_Err( p_filter, "export AtmoInitialize missing.");
  1397. p_sys->pf_ctrl_atmo_finalize =
  1398. (void (*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,
  1399. "AtmoFinalize");
  1400. if(!p_sys->pf_ctrl_atmo_finalize)
  1401. msg_Err( p_filter, "export AtmoFinalize missing.");
  1402. p_sys->pf_ctrl_atmo_switch_effect =
  1403. (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,
  1404. "AtmoSwitchEffect");
  1405. if(!p_sys->pf_ctrl_atmo_switch_effect)
  1406. msg_Err( p_filter, "export AtmoSwitchEffect missing.");
  1407. p_sys->pf_ctrl_atmo_set_live_source =
  1408. (int32_t(*)(int32_t))GetProcAddress(p_sys->h_AtmoCtrl,
  1409. "AtmoSetLiveSource");
  1410. if(!p_sys->pf_ctrl_atmo_set_live_source)
  1411. msg_Err( p_filter, "export AtmoSetLiveSource missing.");
  1412. p_sys->pf_ctrl_atmo_create_transfer_buffers =
  1413. (void (*)(int32_t, int32_t, int32_t , int32_t))
  1414. GetProcAddress(p_sys->h_AtmoCtrl,"AtmoCreateTransferBuffers");
  1415. if(!p_sys->pf_ctrl_atmo_create_transfer_buffers)
  1416. msg_Err( p_filter, "export AtmoCreateTransferBuffers missing.");
  1417. p_sys->pf_ctrl_atmo_lock_transfer_buffer=
  1418. (uint8_t*(*) (void))GetProcAddress(p_sys->h_AtmoCtrl,
  1419. "AtmoLockTransferBuffer");
  1420. if(!p_sys->pf_ctrl_atmo_lock_transfer_buffer)
  1421. msg_Err( p_filter, "export AtmoLockTransferBuffer missing.");
  1422. p_sys->pf_ctrl_atmo_send_pixel_data =
  1423. (void (*)(void))GetProcAddress(p_sys->h_AtmoCtrl,
  1424. "AtmoSendPixelData");
  1425. if(!p_sys->pf_ctrl_atmo_send_pixel_data)
  1426. msg_Err( p_filter, "export AtmoSendPixelData missing.");
  1427. p_sys->pf_ctrl_atmo_get_image_size =
  1428. (void (*)(int32_t*,int32_t*))GetProcAddress(p_sys->h_AtmoCtrl,
  1429. "AtmoWinGetImageSize");
  1430. if(!p_sys->pf_ctrl_atmo_get_image_size)
  1431. msg_Err( p_filter, "export AtmoWinGetImageSize missing.");
  1432. } else {
  1433. /* the DLL is missing try internal filter ...*/
  1434. msg_Warn( p_filter,
  1435. "AtmoCtrlLib.dll missing fallback to internal atmo classic driver");
  1436. p_sys->i_device_type = 1;
  1437. }
  1438. }
  1439. #endif
  1440. if(p_sys->i_device_type >= 1) {
  1441. msg_Dbg( p_filter, "try use buildin driver %d ", p_sys->i_device_type);
  1442. /*
  1443. now we have to read a lof of options from the config dialog
  1444. most important the serial device if not set ... we can skip
  1445. the rest and disable the filter...
  1446. */
  1447. p_sys->p_atmo_config = new CAtmoConfig();
  1448. p_sys->p_atmo_dyndata = new CAtmoDynData(
  1449. (vlc_object_t *)p_filter,
  1450. p_sys->p_atmo_config
  1451. );
  1452. Atmo_SetupConfig( p_filter, p_sys->p_atmo_config );
  1453. switch(p_sys->i_device_type)
  1454. {
  1455. case 1:
  1456. p_sys->p_atmo_config->setConnectionType( actClassicAtmo );
  1457. break;
  1458. case 2:
  1459. p_sys->p_atmo_config->setConnectionType( actMultiAtmo );
  1460. break;
  1461. case 3:
  1462. p_sys->p_atmo_config->setConnectionType( actDMX );
  1463. break;
  1464. case 4:
  1465. p_sys->p_atmo_config->setConnectionType( actMoMoLight );
  1466. break;
  1467. case 5:
  1468. p_sys->p_atmo_config->setConnectionType( actFnordlicht );
  1469. break;
  1470. default:
  1471. msg_Warn( p_filter, "invalid device type %d found",
  1472. p_sys->i_device_type );
  1473. }
  1474. msg_Dbg( p_filter, "buildin driver config set");
  1475. }
  1476. switch( p_filter->fmt_in.video.i_chroma )
  1477. {
  1478. case VLC_CODEC_I420:
  1479. case VLC_CODEC_YV12:
  1480. p_sys->pf_extract_mini_image = ExtractMiniImage_YUV;
  1481. break;
  1482. default:
  1483. msg_Warn( p_filter, "InitFilter-unsupported chroma: %4.4s",
  1484. (char *)&p_filter->fmt_in.video.i_chroma);
  1485. p_sys->pf_extract_mini_image = NULL;
  1486. }
  1487. /*
  1488. for debugging purpose show the samplinggrid on each frame as
  1489. white dots
  1490. */
  1491. p_sys->b_show_dots = var_CreateGetBoolCommand( p_filter,
  1492. CFG_PREFIX "showdots"
  1493. );
  1494. #if defined(__ATMO_DEBUG__)
  1495. /* save debug images to a folder as Bitmap files ? */
  1496. p_sys->b_saveframes = var_CreateGetBoolCommand( p_filter,
  1497. CFG_PREFIX "saveframes"
  1498. );
  1499. msg_Dbg(p_filter,"saveframes = %d", (int)p_sys->b_saveframes);
  1500. /*
  1501. read debug image folder from config
  1502. */
  1503. psz_path = var_CreateGetStringCommand( p_filter, CFG_PREFIX "framepath" );
  1504. if(psz_path != NULL)
  1505. {
  1506. strcpy(p_sys->sz_framepath, psz_path);
  1507. #if defined( WIN32 )
  1508. size_t i_strlen = strlen(p_sys->sz_framepath);
  1509. if((i_strlen>0) && (p_sys->sz_framepath[i_strlen-1] != '\\'))
  1510. {
  1511. p_sys->sz_framepath[i_strlen] = '\\';
  1512. p_sys->sz_framepath[i_strlen+1] = 0;
  1513. }
  1514. #endif
  1515. free(psz_path);
  1516. }
  1517. msg_Dbg(p_filter,"saveframesfolder %s",p_sys->sz_framepath);
  1518. #endif
  1519. /*
  1520. because atmowin could also be used for lighten up the room - I think if you
  1521. pause the video it would be useful to get a little bit more light into to
  1522. your living room? - instead switching on a lamp?
  1523. */
  1524. p_sys->b_usepausecolor = var_CreateGetBoolCommand( p_filter,
  1525. CFG_PREFIX "usepausecolor" );
  1526. p_sys->ui_pausecolor_red = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1527. CFG_PREFIX "pcolor-red");
  1528. p_sys->ui_pausecolor_green = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1529. CFG_PREFIX "pcolor-green");
  1530. p_sys->ui_pausecolor_blue = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1531. CFG_PREFIX "pcolor-blue");
  1532. p_sys->i_fadesteps = var_CreateGetIntegerCommand( p_filter,
  1533. CFG_PREFIX "fadesteps");
  1534. if(p_sys->i_fadesteps < 1)
  1535. p_sys->i_fadesteps = 1;
  1536. msg_Dbg(p_filter,"use pause color %d, RGB: %d, %d, %d, Fadesteps: %d",
  1537. (int)p_sys->b_usepausecolor,
  1538. p_sys->ui_pausecolor_red,
  1539. p_sys->ui_pausecolor_green,
  1540. p_sys->ui_pausecolor_blue,
  1541. p_sys->i_fadesteps);
  1542. /*
  1543. this color is use on shutdown of the filter - the define the
  1544. final light after playback... may be used to dim up the light -
  1545. how it happens in the cinema...
  1546. */
  1547. p_sys->ui_endcolor_red = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1548. CFG_PREFIX "ecolor-red");
  1549. p_sys->ui_endcolor_green = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1550. CFG_PREFIX "ecolor-green");
  1551. p_sys->ui_endcolor_blue = (uint8_t)var_CreateGetIntegerCommand( p_filter,
  1552. CFG_PREFIX "ecolor-blue");
  1553. p_sys->i_endfadesteps = var_CreateGetIntegerCommand( p_filter,
  1554. CFG_PREFIX "efadesteps");
  1555. if(p_sys->i_endfadesteps < 1)
  1556. p_sys->i_endfadesteps = 1;
  1557. msg_Dbg(p_filter,"use ende color RGB: %d, %d, %d, Fadesteps: %d",
  1558. p_sys->ui_endcolor_red,
  1559. p_sys->ui_endcolor_green,
  1560. p_sys->ui_endcolor_blue,
  1561. p_sys->i_endfadesteps);
  1562. /*
  1563. if the external DLL was loaded successfully call AtmoInitialize -
  1564. (must be done for each thread where you want to use AtmoLight!)
  1565. */
  1566. int i = AtmoInitialize(p_filter, false);
  1567. #if defined( WIN32 )
  1568. if((i != 1) && (p_sys->i_device_type == 0))
  1569. {
  1570. /*
  1571. COM Server for AtmoLight not running ?
  1572. if the exe path is configured try to start the "userspace" driver
  1573. */
  1574. psz_path = var_CreateGetStringCommand( p_filter,
  1575. CFG_PREFIX "atmowinexe" );
  1576. if(psz_path != NULL)
  1577. {
  1578. STARTUPINFO startupinfo;
  1579. PROCESS_INFORMATION pinfo;
  1580. memset(&startupinfo, 0, sizeof(STARTUPINFO));
  1581. startupinfo.cb = sizeof(STARTUPINFO);
  1582. if(CreateProcess(psz_path, NULL, NULL, NULL,
  1583. FALSE, 0, NULL, NULL, &startupinfo, &pinfo) == TRUE)
  1584. {
  1585. msg_Dbg(p_filter,"launched AtmoWin from %s",psz_path);
  1586. WaitForInputIdle(pinfo.hProcess, 5000);
  1587. /*
  1588. retry to initialize the library COM ... functionality
  1589. after the server was launched
  1590. */
  1591. i = AtmoInitialize(p_filter, false);
  1592. } else {
  1593. msg_Err(p_filter,"failed to launch AtmoWin from %s", psz_path);
  1594. }
  1595. free(psz_path);
  1596. }
  1597. }
  1598. #endif
  1599. if(i == 1) /* Init Atmolight success... */
  1600. {
  1601. msg_Dbg( p_filter, "AtmoInitialize Ok!");
  1602. /*
  1603. configure
  1604. p_sys->i_atmo_width and p_sys->i_atmo_height
  1605. if the external AtmoWinA.exe is used, it may require
  1606. a other sample image size than 64 x 48
  1607. (this overrides the settings of the filter)
  1608. */
  1609. Atmo_SetupImageSize( p_filter );
  1610. if( p_sys->i_device_type >= 1 )
  1611. {
  1612. /*
  1613. AtmoConnection class initialized now we can initialize
  1614. the default zone and channel mappings
  1615. */
  1616. Atmo_SetupBuildZones( p_filter );
  1617. }
  1618. /* Setup Transferbuffers for 64 x 48 , RGB with 32bit Per Pixel */
  1619. AtmoCreateTransferBuffers(p_filter, BI_RGB, 4,
  1620. p_sys->i_atmo_width,
  1621. p_sys->i_atmo_height
  1622. );
  1623. /* say the userspace driver that a live mode should be activated
  1624. the functions returns the old mode for later restore!
  1625. - the buildin driver launches the live view thread in that case
  1626. */
  1627. p_sys->i_AtmoOldEffect = AtmoSwitchEffect(p_filter, emLivePicture);
  1628. /*
  1629. live view can have two differnt source the AtmoWinA
  1630. internal GDI Screencapture and the external one - which we
  1631. need here...
  1632. */
  1633. AtmoSetLiveSource(p_filter, lvsExternal);
  1634. /* enable other parts only if everything is fine */
  1635. p_sys->b_enabled = true;
  1636. msg_Dbg( p_filter, "Atmo Filter Enabled Ok!");
  1637. }
  1638. }
  1639. /*****************************************************************************
  1640. * CreateFilter: allocates AtmoLight video thread output method
  1641. *****************************************************************************
  1642. * This function allocates and initializes a AtmoLight vout method.
  1643. *****************************************************************************/
  1644. static int CreateFilter( vlc_object_t *p_this )
  1645. {
  1646. filter_t *p_filter = (filter_t *)p_this;
  1647. filter_sys_t *p_sys;
  1648. /* Allocate structure */
  1649. p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
  1650. p_filter->p_sys = p_sys;
  1651. if( p_filter->p_sys == NULL )
  1652. return VLC_ENOMEM;
  1653. /* set all entries to zero */
  1654. memset(p_sys, 0, sizeof( filter_sys_t ));
  1655. vlc_mutex_init( &p_sys->filter_lock );
  1656. msg_Dbg( p_filter, "Create Atmo Filter");
  1657. /* further Setup Function pointers for videolan for calling my filter */
  1658. p_filter->pf_video_filter = Filter;
  1659. config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
  1660. p_filter->p_cfg );
  1661. AddStateVariableCallback(p_filter);
  1662. AddAtmoSettingsVariablesCallbacks(p_filter);
  1663. Atmo_SetupParameters(p_filter);
  1664. return VLC_SUCCESS;
  1665. }
  1666. /*****************************************************************************
  1667. * DestroyFilter: destroy AtmoLight video thread output method
  1668. *****************************************************************************
  1669. * Terminate an output method created by CreateFilter
  1670. *****************************************************************************/
  1671. static void DestroyFilter( vlc_object_t *p_this )
  1672. {
  1673. filter_t *p_filter = (filter_t *)p_this;
  1674. filter_sys_t *p_sys = p_filter->p_sys;
  1675. msg_Dbg( p_filter, "Destroy Atmo Filter");
  1676. DelStateVariableCallback(p_filter);
  1677. DelAtmoSettingsVariablesCallbacks(p_filter);
  1678. Atmo_Shutdown(p_filter);
  1679. #if defined( WIN32 )
  1680. if(p_sys->h_AtmoCtrl != NULL)
  1681. {
  1682. FreeLibrary(p_sys->h_AtmoCtrl);
  1683. }
  1684. #endif
  1685. delete p_sys->p_atmo_dyndata;
  1686. delete p_sys->p_atmo_config;
  1687. vlc_mutex_destroy( &p_sys->filter_lock );
  1688. free( p_sys );
  1689. }
  1690. /*
  1691. function stolen from some other videolan source filter ;-)
  1692. for the moment RGB is OK... but better would be a direct transformation
  1693. from YUV --> HSV
  1694. */
  1695. static inline void yuv_to_rgb( uint8_t *r, uint8_t *g, uint8_t *b,
  1696. uint8_t y1, uint8_t u1, uint8_t v1 )
  1697. {
  1698. /* macros used for YUV pixel conversions */
  1699. # define SCALEBITS 10
  1700. # define ONE_HALF (1 << (SCALEBITS - 1))
  1701. # define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
  1702. # define CLAMP( x ) (((x) > 255) ? 255 : ((x) < 0) ? 0 : (x));
  1703. int y, cb, cr, r_add, g_add, b_add;
  1704. cb = u1 - 128;
  1705. cr = v1 - 128;
  1706. r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
  1707. g_add = - FIX(0.34414*255.0/224.0) * cb
  1708. - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
  1709. b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
  1710. y = (y1 - 16) * FIX(255.0/219.0);
  1711. *r = CLAMP((y + r_add) >> SCALEBITS);
  1712. *g = CLAMP((y + g_add) >> SCALEBITS);
  1713. *b = CLAMP((y + b_add) >> SCALEBITS);
  1714. }
  1715. /******************************************************************************
  1716. * ExtractMiniImage_YUV: extract a small image from the picture as 24-bit RGB
  1717. *******************************************************************************
  1718. * p_sys is a pointer to
  1719. * p_inpic is the source frame
  1720. * p_transfer_dest is the target buffer for the picture must be big enough!
  1721. * (in win32 environment this buffer comes from the external DLL where it is
  1722. * create as "variant array" and returned through the AtmoLockTransferbuffer
  1723. */
  1724. static void ExtractMiniImage_YUV(filter_sys_t *p_sys,
  1725. picture_t *p_inpic,
  1726. uint8_t *p_transfer_dest)
  1727. {
  1728. int i_col;
  1729. int i_row;
  1730. uint8_t *p_src_y;
  1731. uint8_t *p_src_u;
  1732. uint8_t *p_src_v;
  1733. uint8_t *p_rgb_dst_line_red;
  1734. uint8_t *p_rgb_dst_line_green;
  1735. uint8_t *p_rgb_dst_line_blue;
  1736. int i_xpos_y;
  1737. int i_xpos_u;
  1738. int i_xpos_v;
  1739. /* calcute Pointers for Storage of B G R (A) */
  1740. p_rgb_dst_line_blue = p_transfer_dest;
  1741. p_rgb_dst_line_green = p_transfer_dest + 1;
  1742. p_rgb_dst_line_red = p_transfer_dest + 2 ;
  1743. int i_row_count = p_sys->i_atmo_height + 1;
  1744. int i_col_count = p_sys->i_atmo_width + 1;
  1745. int i_y_row,i_u_row,i_v_row,i_pixel_row;
  1746. int i_pixel_col;
  1747. /* these two ugly loops extract the small image - goes it faster? how?
  1748. the loops are so designed that there is a small border around the extracted
  1749. image so we wont get column and row - zero from the frame, and not the most
  1750. right and bottom pixels --- which may be clipped on computers useing TV out
  1751. - through overscan!
  1752. TODO: try to find out if the output is clipped through VLC - and try here
  1753. to ingore the clipped away area for a better result!
  1754. TODO: performance improvement in InitFilter percalculated the offsets of
  1755. the lines inside the planes so I can save (i_row_count * 3) 2xMUL and
  1756. one time DIV the same could be done for the inner loop I think...
  1757. */
  1758. for(i_row = 1; i_row < i_row_count; i_row++)
  1759. {
  1760. // calcute the current Lines in the source planes for this outputrow
  1761. /* Adresscalcuation pointer to plane Length of one pixelrow in bytes
  1762. calculate row now number
  1763. */
  1764. /*
  1765. p_inpic->format? transform Pixel row into row of plane...
  1766. how? simple? fast? good?
  1767. */
  1768. /* compute the source pixel row and respect the active cropping */
  1769. i_pixel_row = (i_row * p_sys->i_crop_height) / i_row_count
  1770. + p_sys->i_crop_y_offset;
  1771. /*
  1772. trans for these Pixel row into the row of each plane ..
  1773. because planesize can differ from image size
  1774. */
  1775. i_y_row = (i_pixel_row * p_inpic->p[Y_PLANE].i_visible_lines) /
  1776. p_inpic->format.i_visible_height;
  1777. i_u_row = (i_pixel_row * p_inpic->p[U_PLANE].i_visible_lines) /
  1778. p_inpic->format.i_visible_height;
  1779. i_v_row = (i_pixel_row * p_inpic->p[V_PLANE].i_visible_lines) /
  1780. p_inpic->format.i_visible_height;
  1781. /* calculate the pointers to the pixeldata for this row
  1782. in each plane
  1783. */
  1784. p_src_y = p_inpic->p[Y_PLANE].p_pixels +
  1785. p_inpic->p[Y_PLANE].i_pitch * i_y_row;
  1786. p_src_u = p_inpic->p[U_PLANE].p_pixels +
  1787. p_inpic->p[U_PLANE].i_pitch * i_u_row;
  1788. p_src_v = p_inpic->p[V_PLANE].p_pixels +
  1789. p_inpic->p[V_PLANE].i_pitch * i_v_row;
  1790. for(i_col = 1; i_col < i_col_count; i_col++)
  1791. {
  1792. i_pixel_col = (i_col * p_sys->i_crop_width) / i_col_count +
  1793. p_sys->i_crop_x_offset;
  1794. /*
  1795. trans for these Pixel row into the row of each plane ..
  1796. because planesize can differ from image size
  1797. */
  1798. i_xpos_y = (i_pixel_col * p_inpic->p[Y_PLANE].i_visible_pitch) /
  1799. p_inpic->format.i_visible_width;
  1800. i_xpos_u = (i_pixel_col * p_inpic->p[U_PLANE].i_visible_pitch) /
  1801. p_inpic->format.i_visible_width;
  1802. i_xpos_v = (i_pixel_col * p_inpic->p[V_PLANE].i_visible_pitch) /
  1803. p_inpic->format.i_visible_width;
  1804. yuv_to_rgb(p_rgb_dst_line_red,
  1805. p_rgb_dst_line_green,
  1806. p_rgb_dst_line_blue,
  1807. p_src_y[i_xpos_y],
  1808. p_src_u[i_xpos_u],
  1809. p_src_v[i_xpos_v]);
  1810. /* +4 because output image should be RGB32 with dword alignment! */
  1811. p_rgb_dst_line_red += 4;
  1812. p_rgb_dst_line_green += 4;
  1813. p_rgb_dst_line_blue += 4;
  1814. }
  1815. }
  1816. if(p_sys->b_show_dots)
  1817. {
  1818. for(i_row = 1; i_row < i_row_count; i_row++)
  1819. {
  1820. i_pixel_row = (i_row * p_sys->i_crop_height) / i_row_count
  1821. + p_sys->i_crop_y_offset;
  1822. i_y_row = (i_pixel_row * p_inpic->p[Y_PLANE].i_visible_lines) /
  1823. p_inpic->format.i_visible_height;
  1824. p_src_y = p_inpic->p[Y_PLANE].p_pixels +
  1825. p_inpic->p[Y_PLANE].i_pitch * i_y_row;
  1826. for(i_col = 1; i_col < i_col_count; i_col++)
  1827. {
  1828. i_pixel_col = (i_col * p_sys->i_crop_width) / i_col_count +
  1829. p_sys->i_crop_x_offset;
  1830. i_xpos_y = (i_pixel_col * p_inpic->p[Y_PLANE].i_visible_pitch) /
  1831. p_inpic->format.i_visible_width;
  1832. p_src_y[i_xpos_y] = 255;
  1833. }
  1834. }
  1835. }
  1836. }
  1837. /******************************************************************************
  1838. * SaveBitmap: Saves the content of a transferbuffer as Bitmap to disk
  1839. *******************************************************************************
  1840. * just for debugging
  1841. * p_sys -> configuration if Atmo from there the function will get height and
  1842. * width
  1843. * p_pixels -> should be the dword aligned BGR(A) image data
  1844. * psz_filename -> filename where to store
  1845. */
  1846. #if defined(__ATMO_DEBUG__)
  1847. void SaveBitmap(filter_sys_t *p_sys, uint8_t *p_pixels, char *psz_filename)
  1848. {
  1849. /* for debug out only used*/
  1850. BITMAPINFO bmp_info;
  1851. BITMAPFILEHEADER bmp_fileheader;
  1852. FILE *fp_bitmap;
  1853. memset(&bmp_info, 0, sizeof(BITMAPINFO));
  1854. bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1855. bmp_info.bmiHeader.biSizeImage = p_sys->i_atmo_height *
  1856. p_sys->i_atmo_width * 4;
  1857. bmp_info.bmiHeader.biCompression = BI_RGB;
  1858. bmp_info.bmiHeader.biWidth = p_sys->i_atmo_width;
  1859. bmp_info.bmiHeader.biHeight = -p_sys->i_atmo_height;
  1860. bmp_info.bmiHeader.biBitCount = 32;
  1861. bmp_info.bmiHeader.biPlanes = 1;
  1862. bmp_fileheader.bfReserved1 = 0;
  1863. bmp_fileheader.bfReserved2 = 0;
  1864. bmp_fileheader.bfSize = sizeof(BITMAPFILEHEADER) +
  1865. sizeof(BITMAPINFOHEADER) +
  1866. bmp_info.bmiHeader.biSizeImage;
  1867. bmp_fileheader.bfType = VLC_TWOCC('B','M');
  1868. bmp_fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) +
  1869. sizeof(BITMAPINFOHEADER);
  1870. fp_bitmap = fopen(psz_filename,"wb");
  1871. if( fp_bitmap != NULL)
  1872. {
  1873. fwrite(&bmp_fileheader, sizeof(BITMAPFILEHEADER), 1, fp_bitmap);
  1874. fwrite(&bmp_info.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp_bitmap);
  1875. fwrite(p_pixels, bmp_info.bmiHeader.biSizeImage, 1, fp_bitmap);
  1876. fclose(fp_bitmap);
  1877. }
  1878. }
  1879. #endif
  1880. /****************************************************************************
  1881. * CreateMiniImage: extracts a 64x48 pixel image from the frame
  1882. * (there is a small border arround thats why the loops starts with one
  1883. * instead zero) without any interpolation
  1884. *****************************************************************************/
  1885. static void CreateMiniImage( filter_t *p_filter, picture_t *p_inpic)
  1886. {
  1887. filter_sys_t *p_sys = p_filter->p_sys;
  1888. /*
  1889. pointer to RGB Buffer created in external libary as safe array which
  1890. is locked inside AtmoLockTransferBuffer
  1891. */
  1892. uint8_t *p_transfer;
  1893. #if defined( __ATMO_DEBUG__ )
  1894. /* for debug out only used*/
  1895. char sz_filename[MAX_PATH];
  1896. #endif
  1897. /*
  1898. Lock the before created VarArray (AtmoCreateTransferBuffers)
  1899. inside my wrapper library and give me a pointer to the buffer!
  1900. below linux a global buffer may be used and protected with a mutex?
  1901. */
  1902. p_transfer = AtmoLockTransferBuffer(p_filter);
  1903. if(p_transfer == NULL)
  1904. {
  1905. msg_Err( p_filter, "AtmoLight no transferbuffer available. "\
  1906. "AtmoLight will be disabled!");
  1907. p_sys->b_enabled = false;
  1908. return;
  1909. }
  1910. /*
  1911. do the call via pointer to function instead of having a
  1912. case structure here
  1913. */
  1914. p_sys->pf_extract_mini_image(p_sys, p_inpic, p_transfer);
  1915. #if defined( __ATMO_DEBUG__ )
  1916. /*
  1917. if debugging enabled save every 128th image to disk
  1918. */
  1919. if((p_sys->b_saveframes == true) && (p_sys->sz_framepath[0] != 0 ))
  1920. {
  1921. if((p_sys->ui_frame_counter & 127) == 0)
  1922. {
  1923. sprintf(sz_filename,"%satmo_dbg_%06u.bmp",p_sys->sz_framepath,
  1924. p_sys->ui_frame_counter);
  1925. msg_Dbg(p_filter, "SaveFrame %s",sz_filename);
  1926. SaveBitmap(p_sys, p_transfer, sz_filename);
  1927. }
  1928. }
  1929. msg_Dbg( p_filter, "AtmoFrame %u Time: %d ms", p_sys->ui_frame_counter,
  1930. mdate() / 1000);
  1931. p_sys->ui_frame_counter++;
  1932. #endif
  1933. p_sys->i_frames_processed++;
  1934. /* show the colors on the wall */
  1935. AtmoSendPixelData( p_filter );
  1936. }
  1937. /*****************************************************************************
  1938. * Filter: calls the extract method and forwards the incomming picture 1:1
  1939. *****************************************************************************
  1940. *
  1941. *****************************************************************************/
  1942. static picture_t * Filter( filter_t *p_filter, picture_t *p_pic )
  1943. {
  1944. filter_sys_t *p_sys = p_filter->p_sys;
  1945. if( !p_pic ) return NULL;
  1946. picture_t *p_outpic = filter_NewPicture( p_filter );
  1947. if( !p_outpic )
  1948. {
  1949. picture_Release( p_pic );
  1950. return NULL;
  1951. }
  1952. picture_CopyPixels( p_outpic, p_pic );
  1953. vlc_mutex_lock( &p_sys->filter_lock );
  1954. if((p_sys->b_enabled == true) &&
  1955. (p_sys->pf_extract_mini_image != NULL) &&
  1956. (p_sys->b_pause_live == false))
  1957. {
  1958. p_sys->i_crop_x_offset = p_filter->fmt_in.video.i_x_offset;
  1959. p_sys->i_crop_y_offset = p_filter->fmt_in.video.i_y_offset;
  1960. p_sys->i_crop_width = p_filter->fmt_in.video.i_visible_width;
  1961. p_sys->i_crop_height = p_filter->fmt_in.video.i_visible_height;
  1962. CreateMiniImage(p_filter, p_outpic);
  1963. }
  1964. vlc_mutex_unlock( &p_sys->filter_lock );
  1965. return CopyInfoAndRelease( p_outpic, p_pic );
  1966. }
  1967. /*****************************************************************************
  1968. * FadeToColorThread: Threadmethod which changes slowly the color
  1969. * to a target color defined in p_fadethread struct
  1970. * use for: Fade to Pause Color, and Fade to End Color
  1971. *****************************************************************************/
  1972. static void *FadeToColorThread(vlc_object_t *obj)
  1973. {
  1974. fadethread_t *p_fadethread = (fadethread_t *)obj;
  1975. filter_sys_t *p_sys = (filter_sys_t *)p_fadethread->p_filter->p_sys;
  1976. int i_steps_done = 0;
  1977. int i_index;
  1978. int i_pause_red;
  1979. int i_pause_green;
  1980. int i_pause_blue;
  1981. int i_src_red;
  1982. int i_src_green;
  1983. int i_src_blue;
  1984. uint8_t *p_source = NULL;
  1985. int canc = vlc_savecancel ();
  1986. /* initialize AtmoWin for this thread! */
  1987. AtmoInitialize(p_fadethread->p_filter , true);
  1988. uint8_t *p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
  1989. if(p_transfer != NULL) {
  1990. /* safe colors as "32bit" Integers to avoid overflows*/
  1991. i_pause_red = p_fadethread->ui_red;
  1992. i_pause_blue = p_fadethread->ui_blue;
  1993. i_pause_green = p_fadethread->ui_green;
  1994. /*
  1995. allocate a temporary buffer for the last send
  1996. image size less then 15kb
  1997. */
  1998. int i_size = 4 * p_sys->i_atmo_width * p_sys->i_atmo_height;
  1999. p_source = (uint8_t *)malloc( i_size );
  2000. if(p_source != NULL)
  2001. {
  2002. /*
  2003. get a copy of the last transfered image as orign for the
  2004. fading steps...
  2005. */
  2006. memcpy(p_source, p_transfer, i_size);
  2007. /* send the same pixel data again... to unlock the buffer! */
  2008. AtmoSendPixelData( p_fadethread->p_filter );
  2009. while( (vlc_object_alive (p_fadethread)) &&
  2010. (i_steps_done < p_fadethread->i_steps))
  2011. {
  2012. p_transfer = AtmoLockTransferBuffer( p_fadethread->p_filter );
  2013. if(!p_transfer) break; /* should not happen if it worked
  2014. one time in the code above! */
  2015. i_steps_done++;
  2016. /*
  2017. move all pixels in the mini image (64x48) one step closer to
  2018. the desired color these loop takes the most time of this
  2019. thread improvements wellcome!
  2020. */
  2021. for(i_index = 0;
  2022. (i_index < i_size) && (vlc_object_alive (p_fadethread));
  2023. i_index+=4)
  2024. {
  2025. i_src_blue = p_source[i_index+0];
  2026. i_src_green = p_source[i_index+1];
  2027. i_src_red = p_source[i_index+2];
  2028. p_transfer[i_index+0] = (uint8_t) (((
  2029. (i_pause_blue - i_src_blue)
  2030. * i_steps_done)/p_fadethread->i_steps)
  2031. + i_src_blue);
  2032. p_transfer[i_index+1] = (uint8_t) (((
  2033. (i_pause_green - i_src_green)
  2034. * i_steps_done)/p_fadethread->i_steps)
  2035. + i_src_green);
  2036. p_transfer[i_index+2] = (uint8_t) (((
  2037. (i_pause_red - i_src_red)
  2038. * i_steps_done)/p_fadethread->i_steps)
  2039. + i_src_red);
  2040. }
  2041. /* send image to lightcontroller */
  2042. AtmoSendPixelData( p_fadethread->p_filter );
  2043. /* is there something like and interruptable sleep inside
  2044. the VLC libaries? inside native win32 I would use an Event
  2045. (CreateEvent) and here an WaitForSingleObject?
  2046. */
  2047. msleep(40000);
  2048. }
  2049. free(p_source);
  2050. } else {
  2051. /* in failure of malloc also unlock buffer */
  2052. AtmoSendPixelData(p_fadethread->p_filter);
  2053. }
  2054. }
  2055. /* call indirect to OleUnitialize() for this thread */
  2056. AtmoFinalize(p_fadethread->p_filter, 0);
  2057. vlc_restorecancel (canc);
  2058. return NULL;
  2059. }
  2060. /*****************************************************************************
  2061. * CheckAndStopFadeThread: if there is a fadethread structure left, or running.
  2062. ******************************************************************************
  2063. * this function will stop the thread ... and waits for its termination
  2064. * before removeing the objects from vout_sys_t ...
  2065. ******************************************************************************/
  2066. static void CheckAndStopFadeThread(filter_t *p_filter)
  2067. {
  2068. filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  2069. vlc_mutex_lock( &p_sys->filter_lock );
  2070. if(p_sys->p_fadethread != NULL)
  2071. {
  2072. msg_Dbg(p_filter, "kill still running fadeing thread...");
  2073. p_sys->p_fadethread->b_die = true;
  2074. vlc_thread_join(p_sys->p_fadethread);
  2075. vlc_object_release(p_sys->p_fadethread);
  2076. p_sys->p_fadethread = NULL;
  2077. }
  2078. vlc_mutex_unlock( &p_sys->filter_lock );
  2079. }
  2080. /*****************************************************************************
  2081. * StateCallback: Callback for the inputs variable "State" to get notified
  2082. * about Pause and Continue Playback events.
  2083. *****************************************************************************/
  2084. static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
  2085. vlc_value_t oldval, vlc_value_t newval,
  2086. void *p_data )
  2087. {
  2088. filter_t *p_filter = (filter_t *)p_data;
  2089. filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  2090. if((p_sys->b_usepausecolor == true) && (p_sys->b_enabled == true))
  2091. {
  2092. msg_Dbg(p_filter, "state change from: %"PRId64" to %"PRId64, oldval.i_int,
  2093. newval.i_int);
  2094. if((newval.i_int == PAUSE_S) && (oldval.i_int == PLAYING_S))
  2095. {
  2096. /* tell the other thread to stop sending images to light
  2097. controller */
  2098. p_sys->b_pause_live = true;
  2099. // clean up old thread - should not happen....
  2100. CheckAndStopFadeThread( p_filter );
  2101. // perpare spawn fadeing thread
  2102. vlc_mutex_lock( &p_sys->filter_lock );
  2103. /*
  2104. launch only a new thread if there is none active!
  2105. or waiting for cleanup
  2106. */
  2107. if(p_sys->p_fadethread == NULL)
  2108. {
  2109. p_sys->p_fadethread = (fadethread_t *)vlc_object_create(
  2110. p_filter,
  2111. sizeof(fadethread_t) );
  2112. p_sys->p_fadethread->p_filter = p_filter;
  2113. p_sys->p_fadethread->ui_red = p_sys->ui_pausecolor_red;
  2114. p_sys->p_fadethread->ui_green = p_sys->ui_pausecolor_green;
  2115. p_sys->p_fadethread->ui_blue = p_sys->ui_pausecolor_blue;
  2116. p_sys->p_fadethread->i_steps = p_sys->i_fadesteps;
  2117. if( vlc_thread_create( p_sys->p_fadethread,
  2118. "AtmoLight fadeing",
  2119. FadeToColorThread,
  2120. VLC_THREAD_PRIORITY_LOW ) )
  2121. {
  2122. msg_Err( p_filter, "cannot create FadeToColorThread" );
  2123. vlc_object_release( p_sys->p_fadethread );
  2124. p_sys->p_fadethread = NULL;
  2125. }
  2126. }
  2127. vlc_mutex_unlock( &p_sys->filter_lock );
  2128. }
  2129. if((newval.i_int == PLAYING_S) && (oldval.i_int == PAUSE_S))
  2130. {
  2131. /* playback continues check thread state */
  2132. CheckAndStopFadeThread( p_filter );
  2133. /* reactivate the Render function... to do its normal work */
  2134. p_sys->b_pause_live = false;
  2135. }
  2136. }
  2137. return VLC_SUCCESS;
  2138. }
  2139. /*****************************************************************************
  2140. * AddPlaylistInputThreadStateCallback: Setup call back on "State" Variable
  2141. *****************************************************************************
  2142. * Add Callback function to the "state" variable of the input thread..
  2143. * first find the PlayList and get the input thread from there to attach
  2144. * my callback?
  2145. *****************************************************************************/
  2146. static void AddStateVariableCallback(filter_t *p_filter)
  2147. {
  2148. input_thread_t *p_input = playlist_CurrentInput( pl_Get( p_filter ) );
  2149. if(p_input)
  2150. {
  2151. var_AddCallback( p_input, "state", StateCallback, p_filter );
  2152. vlc_object_release( p_input );
  2153. }
  2154. }
  2155. /*****************************************************************************
  2156. * DelPlaylistInputThreadStateCallback: Remove call back on "State" Variable
  2157. *****************************************************************************
  2158. * Delete the callback function to the "state" variable of the input thread...
  2159. * first find the PlayList and get the input thread from there to attach
  2160. * my callback? is vlc_object_find the right way for this??
  2161. *****************************************************************************/
  2162. static void DelStateVariableCallback( filter_t *p_filter )
  2163. {
  2164. input_thread_t *p_input = playlist_CurrentInput( pl_Get ( p_filter ) );
  2165. if(p_input)
  2166. {
  2167. var_DelCallback( p_input, "state", StateCallback, p_filter );
  2168. vlc_object_release( p_input );
  2169. }
  2170. }
  2171. /****************************************************************************
  2172. * StateCallback: Callback for the inputs variable "State" to get notified
  2173. * about Pause and Continue Playback events.
  2174. *****************************************************************************/
  2175. static int AtmoSettingsCallback( vlc_object_t *p_this, char const *psz_var,
  2176. vlc_value_t oldval, vlc_value_t newval,
  2177. void *p_data )
  2178. {
  2179. filter_t *p_filter = (filter_t *)p_data;
  2180. filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
  2181. vlc_mutex_lock( &p_sys->filter_lock );
  2182. if( !strcmp( psz_var, CFG_PREFIX "showdots" ))
  2183. {
  2184. p_sys->b_show_dots = newval.b_bool;
  2185. }
  2186. CAtmoConfig *p_atmo_config = p_sys->p_atmo_config;
  2187. if(p_atmo_config)
  2188. {
  2189. msg_Dbg(p_filter, "apply AtmoSettingsCallback %s (int: %"PRId64" -> %"PRId64")",
  2190. psz_var,
  2191. oldval.i_int,
  2192. newval.i_int
  2193. );
  2194. if( !strcmp( psz_var, CFG_PREFIX "filtermode" ))
  2195. p_atmo_config->setLiveViewFilterMode( (AtmoFilterMode)newval.i_int);
  2196. else if( !strcmp( psz_var, CFG_PREFIX "percentnew" ))
  2197. p_atmo_config->setLiveViewFilter_PercentNew( newval.i_int );
  2198. else if( !strcmp( psz_var, CFG_PREFIX "meanlength" ))
  2199. p_atmo_config->setLiveViewFilter_MeanLength( newval.i_int );
  2200. else if( !strcmp( psz_var, CFG_PREFIX "meanthreshold" ))
  2201. p_atmo_config->setLiveViewFilter_MeanThreshold( newval.i_int );
  2202. else if( !strcmp( psz_var, CFG_PREFIX "edgeweightning" ))
  2203. p_atmo_config->setLiveView_EdgeWeighting( newval.i_int );
  2204. else if( !strcmp( psz_var, CFG_PREFIX "brightness" ))
  2205. p_atmo_config->setLiveView_BrightCorrect( newval.i_int );
  2206. else if( !strcmp( psz_var, CFG_PREFIX "darknesslimit" ))
  2207. p_atmo_config->setLiveView_DarknessLimit( newval.i_int );
  2208. else if( !strcmp( psz_var, CFG_PREFIX "huewinsize" ))
  2209. p_atmo_config->setLiveView_HueWinSize( newval.i_int );
  2210. else if( !strcmp( psz_var, CFG_PREFIX "satwinsize" ))
  2211. p_atmo_config->setLiveView_SatWinSize( newval.i_int );
  2212. else if( !strcmp( psz_var, CFG_PREFIX "framedelay" ))
  2213. p_atmo_config->setLiveView_FrameDelay( newval.i_int );
  2214. else if( !strcmp( psz_var, CFG_PREFIX "whiteadj" ))
  2215. p_atmo_config->setUseSoftwareWhiteAdj( newval.b_bool );
  2216. else if( !strcmp( psz_var, CFG_PREFIX "white-red" ))
  2217. p_atmo_config->setWhiteAdjustment_Red( newval.i_int );
  2218. else if( !strcmp( psz_var, CFG_PREFIX "white-green" ))
  2219. p_atmo_config->setWhiteAdjustment_Green( newval.i_int );
  2220. else if( !strcmp( psz_var, CFG_PREFIX "white-blue" ))
  2221. p_atmo_config->setWhiteAdjustment_Blue( newval.i_int );
  2222. }
  2223. vlc_mutex_unlock( &p_sys->filter_lock );
  2224. return VLC_SUCCESS;
  2225. }
  2226. static void AddAtmoSettingsVariablesCallbacks(filter_t *p_filter)
  2227. {
  2228. var_AddCallback( p_filter, CFG_PREFIX "filtermode",
  2229. AtmoSettingsCallback, p_filter );
  2230. var_AddCallback( p_filter, CFG_PREFIX "percentnew",
  2231. AtmoSettingsCallback, p_filter );
  2232. var_AddCallback( p_filter, CFG_PREFIX "meanlength",
  2233. AtmoSettingsCallback, p_filter );
  2234. var_AddCallback( p_filter, CFG_PREFIX "meanthreshold",
  2235. AtmoSettingsCallback, p_filter );
  2236. var_AddCallback( p_filter, CFG_PREFIX "edgeweightning",
  2237. AtmoSettingsCallback, p_filter );
  2238. var_AddCallback( p_filter, CFG_PREFIX "brightness",
  2239. AtmoSettingsCallback, p_filter );
  2240. var_AddCallback( p_filter, CFG_PREFIX "darknesslimit",
  2241. AtmoSettingsCallback, p_filter );
  2242. var_AddCallback( p_filter, CFG_PREFIX "huewinsize",
  2243. AtmoSettingsCallback, p_filter );
  2244. var_AddCallback( p_filter, CFG_PREFIX "satwinsize",
  2245. AtmoSettingsCallback, p_filter );
  2246. var_AddCallback( p_filter, CFG_PREFIX "framedelay",
  2247. AtmoSettingsCallback, p_filter );
  2248. var_AddCallback( p_filter, CFG_PREFIX "whiteadj",
  2249. AtmoSettingsCallback, p_filter );
  2250. var_AddCallback( p_filter, CFG_PREFIX "white-red",
  2251. AtmoSettingsCallback, p_filter );
  2252. var_AddCallback( p_filter, CFG_PREFIX "white-green",
  2253. AtmoSettingsCallback, p_filter );
  2254. var_AddCallback( p_filter, CFG_PREFIX "white-blue",
  2255. AtmoSettingsCallback, p_filter );
  2256. var_AddCallback( p_filter, CFG_PREFIX "showdots",
  2257. AtmoSettingsCallback, p_filter );
  2258. }
  2259. static void DelAtmoSettingsVariablesCallbacks( filter_t *p_filter )
  2260. {
  2261. var_DelCallback( p_filter, CFG_PREFIX "filtermode",
  2262. AtmoSettingsCallback, p_filter );
  2263. var_DelCallback( p_filter, CFG_PREFIX "percentnew",
  2264. AtmoSettingsCallback, p_filter );
  2265. var_DelCallback( p_filter, CFG_PREFIX "meanlength",
  2266. AtmoSettingsCallback, p_filter );
  2267. var_DelCallback( p_filter, CFG_PREFIX "meanthreshold",
  2268. AtmoSettingsCallback, p_filter );
  2269. var_DelCallback( p_filter, CFG_PREFIX "edgeweightning",
  2270. AtmoSettingsCallback, p_filter );
  2271. var_DelCallback( p_filter, CFG_PREFIX "brightness",
  2272. AtmoSettingsCallback, p_filter );
  2273. var_DelCallback( p_filter, CFG_PREFIX "darknesslimit",
  2274. AtmoSettingsCallback, p_filter );
  2275. var_DelCallback( p_filter, CFG_PREFIX "huewinsize",
  2276. AtmoSettingsCallback, p_filter );
  2277. var_DelCallback( p_filter, CFG_PREFIX "satwinsize",
  2278. AtmoSettingsCallback, p_filter );
  2279. var_DelCallback( p_filter, CFG_PREFIX "framedelay",
  2280. AtmoSettingsCallback, p_filter );
  2281. var_DelCallback( p_filter, CFG_PREFIX "whiteadj",
  2282. AtmoSettingsCallback, p_filter );
  2283. var_DelCallback( p_filter, CFG_PREFIX "white-red",
  2284. AtmoSettingsCallback, p_filter );
  2285. var_DelCallback( p_filter, CFG_PREFIX "white-green",
  2286. AtmoSettingsCallback, p_filter );
  2287. var_DelCallback( p_filter, CFG_PREFIX "white-blue",
  2288. AtmoSettingsCallback, p_filter );
  2289. var_DelCallback( p_filter, CFG_PREFIX "showdots",
  2290. AtmoSettingsCallback, p_filter );
  2291. }
  2292. #if defined(__ATMO_DEBUG__)
  2293. static void atmo_parse_crop(char *psz_cropconfig,
  2294. video_format_t fmt_in,
  2295. video_format_t fmt_render,
  2296. int &i_visible_width, int &i_visible_height,
  2297. int &i_x_offset, int &i_y_offset )
  2298. {
  2299. int64_t i_aspect_num, i_aspect_den;
  2300. unsigned int i_width, i_height;
  2301. i_visible_width = fmt_in.i_visible_width;
  2302. i_visible_height = fmt_in.i_visible_height;
  2303. i_x_offset = fmt_in.i_x_offset;
  2304. i_y_offset = fmt_in.i_y_offset;
  2305. char *psz_end = NULL, *psz_parser = strchr( psz_cropconfig, ':' );
  2306. if( psz_parser )
  2307. {
  2308. /* We're using the 3:4 syntax */
  2309. i_aspect_num = strtol( psz_cropconfig, &psz_end, 10 );
  2310. if( psz_end == psz_cropconfig || !i_aspect_num ) return;
  2311. i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
  2312. if( psz_end == psz_parser || !i_aspect_den ) return;
  2313. i_width = fmt_in.i_sar_den * fmt_render.i_visible_height *
  2314. i_aspect_num / i_aspect_den / fmt_in.i_sar_num;
  2315. i_height = fmt_render.i_visible_width*fmt_in.i_sar_num *
  2316. i_aspect_den / i_aspect_num / fmt_in.i_sar_den;
  2317. if( i_width < fmt_render.i_visible_width )
  2318. {
  2319. i_x_offset = fmt_render.i_x_offset +
  2320. (fmt_render.i_visible_width - i_width) / 2;
  2321. i_visible_width = i_width;
  2322. }
  2323. else
  2324. {
  2325. i_y_offset = fmt_render.i_y_offset +
  2326. (fmt_render.i_visible_height - i_height) / 2;
  2327. i_visible_height = i_height;
  2328. }
  2329. }
  2330. else
  2331. {
  2332. psz_parser = strchr( psz_cropconfig, 'x' );
  2333. if( psz_parser )
  2334. {
  2335. /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
  2336. unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
  2337. i_crop_width = strtol( psz_cropconfig, &psz_end, 10 );
  2338. if( psz_end != psz_parser ) return;
  2339. psz_parser = strchr( ++psz_end, '+' );
  2340. i_crop_height = strtol( psz_end, &psz_end, 10 );
  2341. if( psz_end != psz_parser ) return;
  2342. psz_parser = strchr( ++psz_end, '+' );
  2343. i_crop_left = strtol( psz_end, &psz_end, 10 );
  2344. if( psz_end != psz_parser ) return;
  2345. psz_end++;
  2346. i_crop_top = strtol( psz_end, &psz_end, 10 );
  2347. if( *psz_end != '\0' ) return;
  2348. i_width = i_crop_width;
  2349. i_visible_width = i_width;
  2350. i_height = i_crop_height;
  2351. i_visible_height = i_height;
  2352. i_x_offset = i_crop_left;
  2353. i_y_offset = i_crop_top;
  2354. }
  2355. else
  2356. {
  2357. /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
  2358. unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
  2359. psz_parser = strchr( psz_cropconfig, '+' );
  2360. i_crop_left = strtol( psz_cropconfig, &psz_end, 10 );
  2361. if( psz_end != psz_parser ) return;
  2362. psz_parser = strchr( ++psz_end, '+' );
  2363. i_crop_top = strtol( psz_end, &psz_end, 10 );
  2364. if( psz_end != psz_parser ) return;
  2365. psz_parser = strchr( ++psz_end, '+' );
  2366. i_crop_right = strtol( psz_end, &psz_end, 10 );
  2367. if( psz_end != psz_parser ) return;
  2368. psz_end++;
  2369. i_crop_bottom = strtol( psz_end, &psz_end, 10 );
  2370. if( *psz_end != '\0' ) return;
  2371. i_width = fmt_render.i_visible_width -
  2372. i_crop_left -
  2373. i_crop_right;
  2374. i_visible_width = i_width;
  2375. i_height = fmt_render.i_visible_height -
  2376. i_crop_top -
  2377. i_crop_bottom;
  2378. i_visible_height = i_height;
  2379. i_x_offset = i_crop_left;
  2380. i_y_offset = i_crop_top;
  2381. }
  2382. }
  2383. }
  2384. #endif