Advertisement
mmu_man

0001-video_output-add-support-for-Flaschen-Taschen-scre.diff

Jun 11th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.48 KB | None | 0 0
  1. From b088345c496245ad2e00f0b1390677f87ab5ece1 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
  3. Date: Sat, 11 Jun 2016 09:06:23 +0200
  4. Subject: [PATCH] video_output: add support for Flaschen-Taschen screen
  5. protocol
  6.  
  7. cf.
  8. https://github.com/hzeller/flaschen-taschen/blob/master/doc/protocols.md
  9.  
  10. * TODO implement offset_{x,y,z} ? (mostly useful for games though)
  11. * TODO try to fix aspect ratio (it's 1:1 always)
  12. * TODO limit the framerate? It seems like we get lots of errors from net_Write()...
  13. ---
  14. modules/video_output/Makefile.am | 2 +
  15. modules/video_output/flaschen.c | 250 +++++++++++++++++++++++++++++++++++++++
  16. 2 files changed, 252 insertions(+)
  17. create mode 100644 modules/video_output/flaschen.c
  18.  
  19. diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
  20. index e05d02a..24b77ba 100644
  21. --- a/modules/video_output/Makefile.am
  22. +++ b/modules/video_output/Makefile.am
  23. @@ -367,11 +367,13 @@ endif
  24.  
  25.  
  26. ### Common ###
  27. +libflaschen_plugin_la_SOURCES = video_output/flaschen.c
  28. libvdummy_plugin_la_SOURCES = video_output/vdummy.c
  29. libvmem_plugin_la_SOURCES = video_output/vmem.c
  30. libyuv_plugin_la_SOURCES = video_output/yuv.c
  31.  
  32. vout_LTLIBRARIES += \
  33. + libflaschen_plugin.la \
  34. libvdummy_plugin.la \
  35. libvmem_plugin.la \
  36. libyuv_plugin.la
  37. diff --git a/modules/video_output/flaschen.c b/modules/video_output/flaschen.c
  38. new file mode 100644
  39. index 0000000..f4d47e0
  40. --- /dev/null
  41. +++ b/modules/video_output/flaschen.c
  42. @@ -0,0 +1,250 @@
  43. +/*****************************************************************************
  44. + * flaschentaschen.c: Flaschen-Taschen video output display for vlc
  45. + * cf. https://github.com/hzeller/flaschen-taschen
  46. + *****************************************************************************
  47. + * Copyright (C) 2000-2009 VLC authors and VideoLAN
  48. + * Copyright (C) 2016 François Revol <revol@free.fr>
  49. + *
  50. + * Includes code from vdummy.c and aa.c:
  51. + * Authors: Samuel Hocevar <sam@zoy.org>
  52. + * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
  53. + *
  54. + * This program is free software; you can redistribute it and/or modify it
  55. + * under the terms of the GNU Lesser General Public License as published by
  56. + * the Free Software Foundation; either version 2.1 of the License, or
  57. + * (at your option) any later version.
  58. + *
  59. + * This program is distributed in the hope that it will be useful,
  60. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  62. + * GNU Lesser General Public License for more details.
  63. + *
  64. + * You should have received a copy of the GNU Lesser General Public License
  65. + * along with this program; if not, write to the Free Software Foundation,
  66. + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  67. + *****************************************************************************/
  68. +
  69. +/*****************************************************************************
  70. + * Preamble
  71. + *****************************************************************************/
  72. +
  73. +#ifdef HAVE_CONFIG_H
  74. +# include "config.h"
  75. +#endif
  76. +
  77. +#include <vlc_common.h>
  78. +#include <vlc_network.h>
  79. +#include <vlc_plugin.h>
  80. +#include <vlc_vout_display.h>
  81. +
  82. +#define T_FLDISPLAY N_("Flaschen-Taschen display address")
  83. +#define LT_FLDISPLAY N_( \
  84. + "IP address or hostname of the Flaschen-Taschen display. " \
  85. + "Something like ft.noise or ftkleine.noise")
  86. +
  87. +#define T_WIDTH N_("Width")
  88. +#define LT_WIDTH N_("Video width.")
  89. +
  90. +#define T_HEIGHT N_("Height")
  91. +#define LT_HEIGHT N_("Video height.")
  92. +
  93. +/*
  94. + * TODO: implement offset_{x,y,z}
  95. + * TODO: limit the framerate?
  96. + */
  97. +
  98. +static int Open( vlc_object_t * );
  99. +static void Close( vlc_object_t * );
  100. +
  101. +vlc_module_begin ()
  102. + set_shortname( N_("Flaschen") )
  103. + set_description( N_("Flaschen-Taschen video output") )
  104. + set_capability( "vout display", 0 )
  105. + set_callbacks( Open, Close )
  106. + add_shortcut( "flaschen" )
  107. +
  108. + set_category( CAT_VIDEO )
  109. + set_subcategory( SUBCAT_VIDEO_VOUT )
  110. + add_string( "flaschen-display", NULL, T_FLDISPLAY, LT_FLDISPLAY, true )
  111. + add_integer("flaschen-width", 25, T_WIDTH, LT_WIDTH, false)
  112. + add_integer("flaschen-height", 20, T_HEIGHT, LT_HEIGHT, false)
  113. +vlc_module_end ()
  114. +
  115. +
  116. +/*****************************************************************************
  117. + * Local prototypes
  118. + *****************************************************************************/
  119. +struct vout_display_sys_t {
  120. + int fd;
  121. +
  122. + picture_pool_t *pool;
  123. +};
  124. +static picture_pool_t *Pool(vout_display_t *, unsigned count);
  125. +static void Display(vout_display_t *, picture_t *, subpicture_t *);
  126. +static int Control(vout_display_t *, int, va_list);
  127. +
  128. +/*****************************************************************************
  129. + * OpenVideo: activates flaschen vout display method
  130. + *****************************************************************************/
  131. +static int Open(vlc_object_t *object)
  132. +{
  133. + vout_display_t *vd = (vout_display_t *)object;
  134. + vout_display_sys_t *sys;
  135. + int fd;
  136. + unsigned port = 1337;
  137. +
  138. + vd->sys = sys = calloc(1, sizeof(*sys));
  139. + if (!sys)
  140. + return VLC_ENOMEM;
  141. + sys->pool = NULL;
  142. + sys->fd = -1;
  143. +
  144. + /* */
  145. + video_format_t fmt = vd->fmt;
  146. + fmt.i_chroma = VLC_CODEC_RGB24;
  147. + fmt.i_rmask = 0x0000ff;
  148. + fmt.i_gmask = 0x00ff00;
  149. + fmt.i_bmask = 0xff0000;
  150. + fmt.i_width = var_InheritInteger(vd, "flaschen-width");
  151. + fmt.i_height = var_InheritInteger(vd, "flaschen-height");
  152. + fmt.i_visible_width = fmt.i_width;
  153. + fmt.i_visible_height = fmt.i_height;
  154. +
  155. + /* p_vd->info is not modified */
  156. +
  157. + char *display = var_InheritString(vd, "flaschen-display");
  158. + if (!display)
  159. + display = strdup("ftkleine.noise");
  160. + msg_Dbg(vd, "using display at %s (%dx%d)", display, fmt.i_width, fmt.i_height);
  161. +
  162. + fd = net_ConnectDgram( vd, display, port, -1, IPPROTO_UDP );
  163. + free(display);
  164. +
  165. + if( fd == -1 )
  166. + {
  167. + msg_Err( vd,
  168. + "cannot create UDP socket for %s port %u",
  169. + display, port );
  170. + free(sys);
  171. + return VLC_EGENERIC;
  172. + }
  173. + sys->fd = fd;
  174. +
  175. + /* Ignore any unexpected incoming packet */
  176. + setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0 }, sizeof (int));
  177. +
  178. +
  179. + vd->fmt = fmt;
  180. +
  181. + vd->pool = Pool;
  182. + vd->prepare = NULL;
  183. + vd->display = Display;
  184. + vd->control = Control;
  185. + vd->manage = NULL;
  186. +
  187. + vout_display_DeleteWindow(vd, NULL);
  188. +
  189. + return VLC_SUCCESS;
  190. +}
  191. +
  192. +static void Close(vlc_object_t *object)
  193. +{
  194. + vout_display_t *vd = (vout_display_t *)object;
  195. + vout_display_sys_t *sys = vd->sys;
  196. +
  197. + if (sys->pool)
  198. + picture_pool_Release(sys->pool);
  199. +
  200. + net_Close(sys->fd);
  201. + free(sys);
  202. +}
  203. +
  204. +static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
  205. +{
  206. + vout_display_sys_t *sys = vd->sys;
  207. + if (!sys->pool)
  208. + sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
  209. + return sys->pool;
  210. +}
  211. +
  212. +static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
  213. +{
  214. + vout_display_sys_t *sys = vd->sys;
  215. + int result;
  216. + VLC_UNUSED(vd);
  217. + VLC_UNUSED(subpicture);
  218. +
  219. + char *buffer = calloc(1, 64 + vd->fmt.i_width * vd->fmt.i_height * 3);
  220. + if (buffer) {
  221. + int header_len = snprintf(buffer, 64, "P6\n%d %d\n255\n",
  222. + vd->fmt.i_width, vd->fmt.i_height);
  223. + uint8_t *dst = (uint8_t *)buffer + header_len;
  224. + uint8_t *src = picture->p->p_pixels;
  225. + unsigned int l, c;
  226. + for (l = 0; l < vd->fmt.i_height; l++)
  227. + {
  228. + for (c = 0; c < vd->fmt.i_width; c++)
  229. + {
  230. + uint8_t *d = &dst[c*3];
  231. + uint8_t *s = &src[c*3];
  232. + d[0] = s[0];
  233. + d[1] = s[1];
  234. + d[2] = s[2];
  235. + }
  236. + dst += vd->fmt.i_width * 3;
  237. + src += picture->p->i_pitch;
  238. + }
  239. +
  240. +
  241. + result = net_Write(vd, sys->fd, buffer, header_len + vd->fmt.i_width * vd->fmt.i_height * 3);
  242. +
  243. +/* XXX: seems we flood a little, discard errors for now...
  244. + if (result != VLC_SUCCESS)
  245. + {
  246. +perror("send");
  247. + msg_Err(vd, "Error sending datagram %d", result);
  248. + }
  249. +*/
  250. + }
  251. + free(buffer);
  252. + picture_Release(picture);
  253. +}
  254. +
  255. +/**
  256. + * Control for vout display
  257. + */
  258. +static int Control(vout_display_t *vd, int query, va_list args)
  259. +{
  260. + VLC_UNUSED(args);
  261. + vout_display_sys_t *sys = vd->sys;
  262. +
  263. + switch (query) {
  264. + case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
  265. + /* We have to ignore what is requested */
  266. + vout_display_SendEventPicturesInvalid(vd);
  267. + return VLC_SUCCESS;
  268. +
  269. + case VOUT_DISPLAY_RESET_PICTURES:
  270. + if (sys->pool)
  271. + picture_pool_Release(sys->pool);
  272. + sys->pool = NULL;
  273. +
  274. + vd->fmt.i_width = var_InheritInteger(vd, "flaschen-width");
  275. + vd->fmt.i_height = var_InheritInteger(vd, "flaschen-height");
  276. + return VLC_SUCCESS;
  277. +
  278. + case VOUT_DISPLAY_CHANGE_ZOOM:
  279. + case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
  280. + case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
  281. + return VLC_EGENERIC;
  282. +
  283. + case VOUT_DISPLAY_HIDE_MOUSE:
  284. + /* not really working */
  285. + return VLC_SUCCESS;
  286. +
  287. + default:
  288. + msg_Err(vd, "Unsupported query in vout display flaschen");
  289. + return VLC_EGENERIC;
  290. + }
  291. +}
  292. +
  293. --
  294. 2.8.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement