demux: avi: skip empty strf
[vlc.git] / lib / video.c
blobfbb99fbaf43a342ac252b79be127bc884cf8ddec
1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005-2010 VLC authors and VideoLAN
6 * $Id$
8 * Authors: Clément Stenac <zorglub@videolan.org>
9 * Filippo Carone <littlejohn@videolan.org>
10 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
11 * Damien Fouilleul <damienf a_t videolan dot org>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2.1 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc/libvlc.h>
33 #include <vlc/libvlc_renderer_discoverer.h>
34 #include <vlc/libvlc_media.h>
35 #include <vlc/libvlc_media_player.h>
37 #include <vlc_common.h>
38 #include <vlc_modules.h>
39 #include <vlc_input.h>
40 #include <vlc_vout.h>
42 #include "libvlc_internal.h"
43 #include "media_player_internal.h"
44 #include <math.h>
45 #include <assert.h>
48 * Remember to release the returned vout_thread_t.
50 static vout_thread_t **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
52 input_thread_t *p_input = libvlc_get_input_thread( p_mi );
53 if( !p_input )
55 *n = 0;
56 return NULL;
59 vout_thread_t **pp_vouts;
60 if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
62 *n = 0;
63 pp_vouts = NULL;
65 vlc_object_release (p_input);
66 return pp_vouts;
69 static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
71 vout_thread_t *p_vout = NULL;
72 size_t n;
73 vout_thread_t **pp_vouts = GetVouts (mp, &n);
74 if (pp_vouts == NULL)
75 goto err;
77 if (num < n)
78 p_vout = pp_vouts[num];
80 for (size_t i = 0; i < n; i++)
81 if (i != num)
82 vlc_object_release (pp_vouts[i]);
83 free (pp_vouts);
85 if (p_vout == NULL)
86 err:
87 libvlc_printerr ("Video output not active");
88 return p_vout;
91 /**********************************************************************
92 * Exported functions
93 **********************************************************************/
95 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
97 /* This will work even if the video is not currently active */
98 var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
100 /* Apply to current video outputs (if any) */
101 size_t n;
102 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
103 for (size_t i = 0; i < n; i++)
105 var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
106 vlc_object_release (pp_vouts[i]);
108 free (pp_vouts);
111 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
113 return var_GetBool (p_mi, "fullscreen");
116 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
118 bool b_fullscreen = var_ToggleBool (p_mi, "fullscreen");
120 /* Apply to current video outputs (if any) */
121 size_t n;
122 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
123 for (size_t i = 0; i < n; i++)
125 vout_thread_t *p_vout = pp_vouts[i];
127 var_SetBool (p_vout, "fullscreen", b_fullscreen);
128 vlc_object_release (p_vout);
130 free (pp_vouts);
133 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
135 var_SetBool (p_mi, "keyboard-events", !!on);
138 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
140 var_SetBool (p_mi, "mouse-events", !!on);
144 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
145 const char *psz_filepath,
146 unsigned int i_width, unsigned int i_height )
148 assert( psz_filepath );
150 vout_thread_t *p_vout = GetVout (p_mi, num);
151 if (p_vout == NULL)
152 return -1;
154 /* FIXME: This is not atomic. All parameters should be passed at once
155 * (obviously _not_ with var_*()). Also, the libvlc object should not be
156 * used for the callbacks: that breaks badly if there are concurrent
157 * media players in the instance. */
158 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER );
159 var_SetInteger( p_vout, "snapshot-width", i_width);
160 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER );
161 var_SetInteger( p_vout, "snapshot-height", i_height );
162 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING );
163 var_SetString( p_vout, "snapshot-path", psz_filepath );
164 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING );
165 var_SetString( p_vout, "snapshot-format", "png" );
166 var_TriggerCallback( p_vout, "video-snapshot" );
167 vlc_object_release( p_vout );
168 return 0;
171 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
172 unsigned *restrict px, unsigned *restrict py )
174 libvlc_media_track_info_t *info;
175 int ret = -1;
176 if (!p_mi->p_md)
177 return ret;
178 int infos = libvlc_media_get_tracks_info(p_mi->p_md, &info);
179 if (infos <= 0)
180 return ret;
182 for (int i = 0; i < infos; i++)
183 if (info[i].i_type == libvlc_track_video && num-- == 0) {
184 *px = info[i].u.video.i_width;
185 *py = info[i].u.video.i_height;
186 ret = 0;
187 break;
190 free(info);
191 return ret;
194 int libvlc_video_get_height( libvlc_media_player_t *p_mi )
196 unsigned width, height;
198 if (libvlc_video_get_size (p_mi, 0, &width, &height))
199 return 0;
200 return height;
203 int libvlc_video_get_width( libvlc_media_player_t *p_mi )
205 unsigned width, height;
207 if (libvlc_video_get_size (p_mi, 0, &width, &height))
208 return 0;
209 return width;
212 int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
213 int *restrict px, int *restrict py )
215 vout_thread_t *p_vout = GetVout (mp, num);
216 if (p_vout == NULL)
217 return -1;
219 var_GetCoords (p_vout, "mouse-moved", px, py);
220 vlc_object_release (p_vout);
221 return 0;
224 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
226 size_t n;
227 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
228 for (size_t i = 0; i < n; i++)
229 vlc_object_release (pp_vouts[i]);
230 free (pp_vouts);
231 return n;
234 float libvlc_video_get_scale( libvlc_media_player_t *mp )
236 float f_scale = var_GetFloat (mp, "zoom");
237 if (var_GetBool (mp, "autoscale"))
238 f_scale = 0.f;
239 return f_scale;
242 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
244 if (isfinite(f_scale) && f_scale != 0.f)
245 var_SetFloat (p_mp, "zoom", f_scale);
246 var_SetBool (p_mp, "autoscale", f_scale == 0.f);
248 /* Apply to current video outputs (if any) */
249 size_t n;
250 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
251 for (size_t i = 0; i < n; i++)
253 vout_thread_t *p_vout = pp_vouts[i];
255 if (isfinite(f_scale) && f_scale != 0.f)
256 var_SetFloat (p_vout, "zoom", f_scale);
257 var_SetBool (p_vout, "autoscale", f_scale == 0.f);
258 vlc_object_release (p_vout);
260 free (pp_vouts);
263 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
265 return var_GetNonEmptyString (p_mi, "aspect-ratio");
268 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
269 const char *psz_aspect )
271 if (psz_aspect == NULL)
272 psz_aspect = "";
273 var_SetString (p_mi, "aspect-ratio", psz_aspect);
275 size_t n;
276 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
277 for (size_t i = 0; i < n; i++)
279 vout_thread_t *p_vout = pp_vouts[i];
281 var_SetString (p_vout, "aspect-ratio", psz_aspect);
282 vlc_object_release (p_vout);
284 free (pp_vouts);
287 libvlc_video_viewpoint_t *libvlc_video_new_viewpoint(void)
289 libvlc_video_viewpoint_t *p_vp = malloc(sizeof *p_vp);
290 if (unlikely(p_vp == NULL))
291 return NULL;
292 p_vp->f_yaw = p_vp->f_pitch = p_vp->f_roll = p_vp->f_field_of_view = 0.0f;
293 return p_vp;
296 int libvlc_video_update_viewpoint( libvlc_media_player_t *p_mi,
297 const libvlc_video_viewpoint_t *p_viewpoint,
298 bool b_absolute )
300 vlc_viewpoint_t update = {
301 .yaw = p_viewpoint->f_yaw,
302 .pitch = p_viewpoint->f_pitch,
303 .roll = p_viewpoint->f_roll,
304 .fov = p_viewpoint->f_field_of_view,
307 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
308 if( p_input_thread != NULL )
310 if( input_UpdateViewpoint( p_input_thread, &update,
311 b_absolute ) != VLC_SUCCESS )
313 vlc_object_release( p_input_thread );
314 return -1;
316 vlc_object_release( p_input_thread );
317 return 0;
320 /* Save the viewpoint in case the input is not created yet */
321 if( !b_absolute )
323 p_mi->viewpoint.yaw += update.yaw;
324 p_mi->viewpoint.pitch += update.pitch;
325 p_mi->viewpoint.roll += update.roll;
326 p_mi->viewpoint.fov += update.fov;
328 else
329 p_mi->viewpoint = update;
331 return 0;
334 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
336 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
338 if( !p_input_thread )
340 libvlc_printerr( "No active input" );
341 return -1;
344 int i_spu = var_GetInteger( p_input_thread, "spu-es" );
345 vlc_object_release( p_input_thread );
346 return i_spu;
349 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
351 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
352 int i_spu_count;
354 if( !p_input_thread )
355 return 0;
357 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
358 vlc_object_release( p_input_thread );
359 return i_spu_count;
362 libvlc_track_description_t *
363 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
365 return libvlc_get_track_description( p_mi, "spu-es" );
368 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
370 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
371 vlc_value_t list;
372 int i_ret = -1;
374 if( !p_input_thread )
375 return -1;
377 var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
378 for (int i = 0; i < list.p_list->i_count; i++)
380 if( i_spu == list.p_list->p_values[i].i_int )
382 if( var_SetInteger( p_input_thread, "spu-es", i_spu ) < 0 )
383 break;
384 i_ret = 0;
385 goto end;
388 libvlc_printerr( "Track identifier not found" );
389 end:
390 vlc_object_release (p_input_thread);
391 var_FreeList (&list, NULL);
392 return i_ret;
395 int libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi,
396 const char *psz_subtitle )
398 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
399 bool b_ret = false;
401 if( p_input_thread )
403 if( !input_AddSubtitle( p_input_thread, psz_subtitle, true ) )
404 b_ret = true;
405 vlc_object_release( p_input_thread );
407 return b_ret;
410 int64_t libvlc_video_get_spu_delay( libvlc_media_player_t *p_mi )
412 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
413 int64_t val = 0;
415 if( p_input_thread )
417 val = var_GetInteger( p_input_thread, "spu-delay" );
418 vlc_object_release( p_input_thread );
420 else
422 libvlc_printerr( "No active input" );
425 return val;
428 int libvlc_video_set_spu_delay( libvlc_media_player_t *p_mi,
429 int64_t i_delay )
431 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
432 int ret = -1;
434 if( p_input_thread )
436 var_SetInteger( p_input_thread, "spu-delay", i_delay );
437 vlc_object_release( p_input_thread );
438 ret = 0;
440 else
442 libvlc_printerr( "No active input" );
445 return ret;
448 libvlc_track_description_t *
449 libvlc_video_get_title_description( libvlc_media_player_t *p_mi )
451 return libvlc_get_track_description( p_mi, "title" );
454 libvlc_track_description_t *
455 libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi,
456 int i_title )
458 char psz_title[sizeof ("title ") + 3 * sizeof (int)];
459 sprintf( psz_title, "title %2u", i_title );
460 return libvlc_get_track_description( p_mi, psz_title );
463 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
465 return var_GetNonEmptyString (p_mi, "crop");
468 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
469 const char *psz_geometry )
471 if (psz_geometry == NULL)
472 psz_geometry = "";
474 var_SetString (p_mi, "crop", psz_geometry);
476 size_t n;
477 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
479 for (size_t i = 0; i < n; i++)
481 vout_thread_t *p_vout = pp_vouts[i];
483 var_SetString (p_vout, "crop", psz_geometry);
484 vlc_object_release (p_vout);
486 free (pp_vouts);
489 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
491 return var_GetInteger (p_mi, "vbi-page");
494 static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
496 if( b_enable )
498 vlc_value_t list;
499 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
500 &list, NULL ) )
502 if( list.p_list->i_count > 0 )
503 var_SetInteger( p_input_thread, "spu-es",
504 list.p_list->p_values[0].i_int );
506 var_FreeList( &list, NULL );
509 else
510 var_SetInteger( p_input_thread, "spu-es", -1 );
513 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
515 input_thread_t *p_input_thread;
516 vlc_object_t *p_zvbi = NULL;
517 int telx;
518 bool b_key = false;
520 if( i_page >= 0 && i_page < 1000 )
521 var_SetInteger( p_mi, "vbi-page", i_page );
522 else if( i_page >= 1000 )
524 switch (i_page)
526 case libvlc_teletext_key_red:
527 case libvlc_teletext_key_green:
528 case libvlc_teletext_key_yellow:
529 case libvlc_teletext_key_blue:
530 case libvlc_teletext_key_index:
531 b_key = true;
532 break;
533 default:
534 libvlc_printerr("Invalid key action");
535 return;
538 else
540 libvlc_printerr("Invalid page number");
541 return;
544 p_input_thread = libvlc_get_input_thread( p_mi );
545 if( !p_input_thread ) return;
547 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
549 vlc_object_release( p_input_thread );
550 return;
553 if( i_page == 0 )
555 teletext_enable( p_input_thread, false );
557 else
559 telx = var_GetInteger( p_input_thread, "teletext-es" );
560 if( telx >= 0 )
562 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
563 == VLC_SUCCESS )
565 var_SetInteger( p_zvbi, "vbi-page", i_page );
566 vlc_object_release( p_zvbi );
569 else if (!b_key)
571 /* the "vbi-page" will be selected on es creation */
572 teletext_enable( p_input_thread, true );
574 else
575 libvlc_printerr("Key action sent while the teletext is disabled");
577 vlc_object_release( p_input_thread );
580 void libvlc_toggle_teletext( libvlc_media_player_t *p_mi )
582 input_thread_t *p_input_thread;
584 p_input_thread = libvlc_get_input_thread(p_mi);
585 if( !p_input_thread ) return;
587 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
589 vlc_object_release( p_input_thread );
590 return;
592 const bool b_selected = var_GetInteger( p_input_thread, "teletext-es" ) >= 0;
593 teletext_enable( p_input_thread, !b_selected );
594 vlc_object_release( p_input_thread );
597 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
599 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
600 int i_track_count;
602 if( !p_input_thread )
603 return -1;
605 i_track_count = var_CountChoices( p_input_thread, "video-es" );
607 vlc_object_release( p_input_thread );
608 return i_track_count;
611 libvlc_track_description_t *
612 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
614 return libvlc_get_track_description( p_mi, "video-es" );
617 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
619 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
621 if( !p_input_thread )
622 return -1;
624 int id = var_GetInteger( p_input_thread, "video-es" );
625 vlc_object_release( p_input_thread );
626 return id;
629 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
631 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
632 vlc_value_t val_list;
633 int i_ret = -1;
635 if( !p_input_thread )
636 return -1;
638 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
639 for( int i = 0; i < val_list.p_list->i_count; i++ )
641 if( i_track == val_list.p_list->p_values[i].i_int )
643 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
644 break;
645 i_ret = 0;
646 goto end;
649 libvlc_printerr( "Track identifier not found" );
650 end:
651 var_FreeList( &val_list, NULL );
652 vlc_object_release( p_input_thread );
653 return i_ret;
656 /******************************************************************************
657 * libvlc_video_set_deinterlace : enable deinterlace
658 *****************************************************************************/
659 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi,
660 const char *psz_mode )
662 if (psz_mode == NULL)
663 psz_mode = "";
664 if (*psz_mode
665 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
666 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
667 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
668 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x")
669 && strcmp (psz_mode, "phosphor") && strcmp (psz_mode, "ivtc"))
670 return;
672 if (*psz_mode)
674 var_SetString (p_mi, "deinterlace-mode", psz_mode);
675 var_SetInteger (p_mi, "deinterlace", 1);
677 else
678 var_SetInteger (p_mi, "deinterlace", 0);
680 size_t n;
681 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
682 for (size_t i = 0; i < n; i++)
684 vout_thread_t *p_vout = pp_vouts[i];
686 if (*psz_mode)
688 var_SetString (p_vout, "deinterlace-mode", psz_mode);
689 var_SetInteger (p_vout, "deinterlace", 1);
691 else
692 var_SetInteger (p_vout, "deinterlace", 0);
693 vlc_object_release (p_vout);
695 free (pp_vouts);
698 /* ************** */
699 /* module helpers */
700 /* ************** */
702 static int get_filter_str( vlc_object_t *p_parent, const char *psz_name,
703 bool b_add, const char **ppsz_filter_type,
704 char **ppsz_filter_value)
706 char *psz_parser;
707 char *psz_string;
708 const char *psz_filter_type;
710 module_t *p_obj = module_find( psz_name );
711 if( !p_obj )
713 msg_Err( p_parent, "Unable to find filter module \"%s\".", psz_name );
714 return VLC_EGENERIC;
717 if( module_provides( p_obj, "video filter" ) )
719 psz_filter_type = "video-filter";
721 else if( module_provides( p_obj, "sub source" ) )
723 psz_filter_type = "sub-source";
725 else if( module_provides( p_obj, "sub filter" ) )
727 psz_filter_type = "sub-filter";
729 else
731 msg_Err( p_parent, "Unknown video filter type." );
732 return VLC_EGENERIC;
735 psz_string = var_GetString( p_parent, psz_filter_type );
737 /* Todo : Use some generic chain manipulation functions */
738 if( !psz_string ) psz_string = strdup("");
740 psz_parser = strstr( psz_string, psz_name );
741 if( b_add )
743 if( !psz_parser )
745 psz_parser = psz_string;
746 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
747 psz_string, psz_name ) == -1 )
749 free( psz_parser );
750 return VLC_EGENERIC;
752 free( psz_parser );
754 else
756 free( psz_string );
757 return VLC_EGENERIC;
760 else
762 if( psz_parser )
764 memmove( psz_parser, psz_parser + strlen(psz_name) +
765 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
766 strlen(psz_parser + strlen(psz_name)) + 1 );
768 /* Remove trailing : : */
769 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
770 *(psz_string+strlen(psz_string ) -1 ) = '\0';
772 else
774 free( psz_string );
775 return VLC_EGENERIC;
779 *ppsz_filter_type = psz_filter_type;
780 *ppsz_filter_value = psz_string;
781 return VLC_SUCCESS;
784 static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *restrict name )
786 vout_thread_t *vout = GetVout( p_mi, 0 );
787 if (!vout)
788 return false;
790 char *psz_sources = var_GetString( vout, "sub-source" );
791 if( !psz_sources )
793 libvlc_printerr( "%s not enabled", name );
794 vlc_object_release( vout );
795 return false;
798 /* Find 'name' */
799 char *p = strstr( psz_sources, name );
800 free( psz_sources );
801 vlc_object_release( vout );
802 return (p != NULL);
805 typedef const struct {
806 const char name[20];
807 unsigned type;
808 } opt_t;
810 static void
811 set_value( libvlc_media_player_t *p_mi, const char *restrict name,
812 const opt_t *restrict opt, unsigned i_expected_type,
813 const vlc_value_t *val, bool b_sub_source )
815 if( !opt ) return;
817 int i_type = opt->type;
818 vlc_value_t new_val = *val;
819 const char *psz_opt_name = opt->name;
820 switch( i_type )
822 case 0: /* the enabler */
824 int i_ret = get_filter_str( VLC_OBJECT( p_mi ), opt->name, val->i_int,
825 &psz_opt_name, &new_val.psz_string );
826 if( i_ret != VLC_SUCCESS )
827 return;
828 i_type = VLC_VAR_STRING;
829 break;
831 case VLC_VAR_INTEGER:
832 case VLC_VAR_FLOAT:
833 case VLC_VAR_STRING:
834 if( i_expected_type != opt->type )
836 libvlc_printerr( "Invalid argument to %s", name );
837 return;
839 break;
840 default:
841 libvlc_printerr( "Invalid argument to %s", name );
842 return;
845 /* Set the new value to the media player. Next vouts created from this
846 * media player will inherit this new value */
847 var_SetChecked( p_mi, psz_opt_name, i_type, new_val );
849 /* Set the new value to every loaded vouts */
850 size_t i_vout_count;
851 vout_thread_t **pp_vouts = GetVouts( p_mi, &i_vout_count );
852 for( size_t i = 0; i < i_vout_count; ++i )
854 var_SetChecked( pp_vouts[i], psz_opt_name, i_type, new_val );
855 if( b_sub_source )
856 var_TriggerCallback( pp_vouts[i], "sub-source" );
857 vlc_object_release( pp_vouts[i] );
860 if( opt->type == 0 )
861 free( new_val.psz_string );
864 static int
865 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
866 const opt_t *restrict opt )
868 if( !opt ) return 0;
870 switch( opt->type )
872 case 0: /* the enabler */
874 bool b_enabled = find_sub_source_by_name( p_mi, name );
875 return b_enabled ? 1 : 0;
877 case VLC_VAR_INTEGER:
878 return var_GetInteger(p_mi, opt->name);
879 case VLC_VAR_FLOAT:
880 return lroundf(var_GetFloat(p_mi, opt->name));
881 default:
882 libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
883 return 0;
887 static float
888 get_float( libvlc_media_player_t *p_mi, const char *restrict name,
889 const opt_t *restrict opt )
891 if( !opt ) return 0.0;
893 if( opt->type != VLC_VAR_FLOAT )
895 libvlc_printerr( "Invalid argument to %s in %s", name, "get float" );
896 return 0.0;
899 return var_GetFloat( p_mi, opt->name );
902 static char *
903 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
904 const opt_t *restrict opt )
906 if( !opt ) return NULL;
908 if( opt->type != VLC_VAR_STRING )
910 libvlc_printerr( "Invalid argument to %s in %s", name, "get string" );
911 return NULL;
914 return var_GetString( p_mi, opt->name );
917 static const opt_t *
918 marq_option_bynumber(unsigned option)
920 static const opt_t optlist[] =
922 { "marq", 0 },
923 { "marq-marquee", VLC_VAR_STRING },
924 { "marq-color", VLC_VAR_INTEGER },
925 { "marq-opacity", VLC_VAR_INTEGER },
926 { "marq-position", VLC_VAR_INTEGER },
927 { "marq-refresh", VLC_VAR_INTEGER },
928 { "marq-size", VLC_VAR_INTEGER },
929 { "marq-timeout", VLC_VAR_INTEGER },
930 { "marq-x", VLC_VAR_INTEGER },
931 { "marq-y", VLC_VAR_INTEGER },
933 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
935 const opt_t *r = option < num_opts ? optlist+option : NULL;
936 if( !r )
937 libvlc_printerr( "Unknown marquee option" );
938 return r;
941 /*****************************************************************************
942 * libvlc_video_get_marquee_int : get a marq option value
943 *****************************************************************************/
944 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
945 unsigned option )
947 return get_int( p_mi, "marq", marq_option_bynumber(option) );
950 /*****************************************************************************
951 * libvlc_video_get_marquee_string : get a marq option value
952 *****************************************************************************/
953 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
954 unsigned option )
956 return get_string( p_mi, "marq", marq_option_bynumber(option) );
959 /*****************************************************************************
960 * libvlc_video_set_marquee_int: enable, disable or set an int option
961 *****************************************************************************/
962 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
963 unsigned option, int value )
965 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_INTEGER,
966 &(vlc_value_t) { .i_int = value }, true );
969 /*****************************************************************************
970 * libvlc_video_set_marquee_string: set a string option
971 *****************************************************************************/
972 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
973 unsigned option, const char * value )
975 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_STRING,
976 &(vlc_value_t){ .psz_string = (char *)value }, true );
980 /* logo module support */
982 static const opt_t *
983 logo_option_bynumber( unsigned option )
985 static const opt_t vlogo_optlist[] =
986 /* depends on libvlc_video_logo_option_t */
988 { "logo", 0 },
989 { "logo-file", VLC_VAR_STRING },
990 { "logo-x", VLC_VAR_INTEGER },
991 { "logo-y", VLC_VAR_INTEGER },
992 { "logo-delay", VLC_VAR_INTEGER },
993 { "logo-repeat", VLC_VAR_INTEGER },
994 { "logo-opacity", VLC_VAR_INTEGER },
995 { "logo-position", VLC_VAR_INTEGER },
997 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
999 const opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
1000 if( !r )
1001 libvlc_printerr( "Unknown logo option" );
1002 return r;
1005 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
1006 unsigned option, const char *psz_value )
1008 set_value( p_mi,"logo",logo_option_bynumber(option), VLC_VAR_STRING,
1009 &(vlc_value_t){ .psz_string = (char *)psz_value }, true );
1013 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
1014 unsigned option, int value )
1016 set_value( p_mi, "logo", logo_option_bynumber(option), VLC_VAR_INTEGER,
1017 &(vlc_value_t) { .i_int = value }, true );
1021 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
1022 unsigned option )
1024 return get_int( p_mi, "logo", logo_option_bynumber(option) );
1028 /* adjust module support */
1031 static const opt_t *
1032 adjust_option_bynumber( unsigned option )
1034 static const opt_t optlist[] =
1036 { "adjust", 0 },
1037 { "contrast", VLC_VAR_FLOAT },
1038 { "brightness", VLC_VAR_FLOAT },
1039 { "hue", VLC_VAR_FLOAT },
1040 { "saturation", VLC_VAR_FLOAT },
1041 { "gamma", VLC_VAR_FLOAT },
1043 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
1045 const opt_t *r = option < num_opts ? optlist+option : NULL;
1046 if( !r )
1047 libvlc_printerr( "Unknown adjust option" );
1048 return r;
1052 void libvlc_video_set_adjust_int( libvlc_media_player_t *p_mi,
1053 unsigned option, int value )
1055 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_INTEGER,
1056 &(vlc_value_t) { .i_int = value }, false );
1060 int libvlc_video_get_adjust_int( libvlc_media_player_t *p_mi,
1061 unsigned option )
1063 return get_int( p_mi, "adjust", adjust_option_bynumber(option) );
1067 void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
1068 unsigned option, float value )
1070 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_FLOAT,
1071 &(vlc_value_t) { .f_float = value }, false );
1075 float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
1076 unsigned option )
1078 return get_float( p_mi, "adjust", adjust_option_bynumber(option) );