PageRenderTime 77ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/VLC-1.1.0-iOS/modules/video_filter/atmo/atmo.cpp

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