demux: mp4: use struct for coreaudio layout params
[vlc.git] / lib / video.c
blobfc964955b455141e1c661c9b454836699e782e91
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_picture.h>
35 #include <vlc/libvlc_media.h>
36 #include <vlc/libvlc_media_player.h>
38 #include <vlc_common.h>
39 #include <vlc_modules.h>
40 #include <vlc_input.h>
41 #include <vlc_vout.h>
42 #include <vlc_url.h>
44 #include "libvlc_internal.h"
45 #include "media_player_internal.h"
46 #include <math.h>
47 #include <assert.h>
50 * Remember to release the returned vout_thread_t.
52 static vout_thread_t **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
54 input_thread_t *p_input = libvlc_get_input_thread( p_mi );
55 if( !p_input )
57 *n = 0;
58 return NULL;
61 vout_thread_t **pp_vouts;
62 if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
64 *n = 0;
65 pp_vouts = NULL;
67 vlc_object_release (p_input);
68 return pp_vouts;
71 static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
73 vout_thread_t *p_vout = NULL;
74 size_t n;
75 vout_thread_t **pp_vouts = GetVouts (mp, &n);
76 if (pp_vouts == NULL)
77 goto err;
79 if (num < n)
80 p_vout = pp_vouts[num];
82 for (size_t i = 0; i < n; i++)
83 if (i != num)
84 vlc_object_release (pp_vouts[i]);
85 free (pp_vouts);
87 if (p_vout == NULL)
88 err:
89 libvlc_printerr ("Video output not active");
90 return p_vout;
93 /**********************************************************************
94 * Exported functions
95 **********************************************************************/
97 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
99 /* This will work even if the video is not currently active */
100 var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
102 /* Apply to current video outputs (if any) */
103 size_t n;
104 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
105 for (size_t i = 0; i < n; i++)
107 var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
108 vlc_object_release (pp_vouts[i]);
110 free (pp_vouts);
113 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
115 return var_GetBool (p_mi, "fullscreen");
118 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
120 bool b_fullscreen = var_ToggleBool (p_mi, "fullscreen");
122 /* Apply to current video outputs (if any) */
123 size_t n;
124 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
125 for (size_t i = 0; i < n; i++)
127 vout_thread_t *p_vout = pp_vouts[i];
129 var_SetBool (p_vout, "fullscreen", b_fullscreen);
130 vlc_object_release (p_vout);
132 free (pp_vouts);
135 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
137 var_SetBool (p_mi, "keyboard-events", !!on);
140 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
142 var_SetBool (p_mi, "mouse-events", !!on);
146 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
147 const char *psz_filepath,
148 unsigned int i_width, unsigned int i_height )
150 assert( psz_filepath );
152 vout_thread_t *p_vout = GetVout (p_mi, num);
153 if (p_vout == NULL)
154 return -1;
156 /* FIXME: This is not atomic. All parameters should be passed at once
157 * (obviously _not_ with var_*()). Also, the libvlc object should not be
158 * used for the callbacks: that breaks badly if there are concurrent
159 * media players in the instance. */
160 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER );
161 var_SetInteger( p_vout, "snapshot-width", i_width);
162 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER );
163 var_SetInteger( p_vout, "snapshot-height", i_height );
164 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING );
165 var_SetString( p_vout, "snapshot-path", psz_filepath );
166 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING );
167 var_SetString( p_vout, "snapshot-format", "png" );
168 var_TriggerCallback( p_vout, "video-snapshot" );
169 vlc_object_release( p_vout );
170 return 0;
173 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
174 unsigned *restrict px, unsigned *restrict py )
176 if (p_mi->p_md == NULL)
177 return -1;
179 libvlc_media_track_t **tracks;
180 unsigned count = libvlc_media_tracks_get(p_mi->p_md, &tracks);
181 int ret = -1;
183 for (unsigned i = 0; i < count; i++)
184 if (tracks[i]->i_type == libvlc_track_video && num-- == 0) {
185 *px = tracks[i]->video->i_width;
186 *py = tracks[i]->video->i_height;
187 ret = 0;
188 break;
191 libvlc_media_tracks_release(tracks, count);
192 return ret;
195 int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
196 int *restrict px, int *restrict py )
198 vout_thread_t *p_vout = GetVout (mp, num);
199 if (p_vout == NULL)
200 return -1;
202 var_GetCoords (p_vout, "mouse-moved", px, py);
203 vlc_object_release (p_vout);
204 return 0;
207 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
209 size_t n;
210 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
211 for (size_t i = 0; i < n; i++)
212 vlc_object_release (pp_vouts[i]);
213 free (pp_vouts);
214 return n;
217 float libvlc_video_get_scale( libvlc_media_player_t *mp )
219 float f_scale = var_GetFloat (mp, "zoom");
220 if (var_GetBool (mp, "autoscale"))
221 f_scale = 0.f;
222 return f_scale;
225 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
227 if (isfinite(f_scale) && f_scale != 0.f)
228 var_SetFloat (p_mp, "zoom", f_scale);
229 var_SetBool (p_mp, "autoscale", f_scale == 0.f);
231 /* Apply to current video outputs (if any) */
232 size_t n;
233 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
234 for (size_t i = 0; i < n; i++)
236 vout_thread_t *p_vout = pp_vouts[i];
238 if (isfinite(f_scale) && f_scale != 0.f)
239 var_SetFloat (p_vout, "zoom", f_scale);
240 var_SetBool (p_vout, "autoscale", f_scale == 0.f);
241 vlc_object_release (p_vout);
243 free (pp_vouts);
246 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
248 return var_GetNonEmptyString (p_mi, "aspect-ratio");
251 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
252 const char *psz_aspect )
254 if (psz_aspect == NULL)
255 psz_aspect = "";
256 var_SetString (p_mi, "aspect-ratio", psz_aspect);
258 size_t n;
259 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
260 for (size_t i = 0; i < n; i++)
262 vout_thread_t *p_vout = pp_vouts[i];
264 var_SetString (p_vout, "aspect-ratio", psz_aspect);
265 vlc_object_release (p_vout);
267 free (pp_vouts);
270 libvlc_video_viewpoint_t *libvlc_video_new_viewpoint(void)
272 libvlc_video_viewpoint_t *p_vp = malloc(sizeof *p_vp);
273 if (unlikely(p_vp == NULL))
274 return NULL;
275 p_vp->f_yaw = p_vp->f_pitch = p_vp->f_roll = p_vp->f_field_of_view = 0.0f;
276 return p_vp;
279 int libvlc_video_update_viewpoint( libvlc_media_player_t *p_mi,
280 const libvlc_video_viewpoint_t *p_viewpoint,
281 bool b_absolute )
283 vlc_viewpoint_t update = {
284 .yaw = p_viewpoint->f_yaw,
285 .pitch = p_viewpoint->f_pitch,
286 .roll = p_viewpoint->f_roll,
287 .fov = p_viewpoint->f_field_of_view,
290 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
291 if( p_input_thread != NULL )
293 if( input_UpdateViewpoint( p_input_thread, &update,
294 b_absolute ) != VLC_SUCCESS )
296 vlc_object_release( p_input_thread );
297 return -1;
299 vlc_object_release( p_input_thread );
300 return 0;
303 /* Save the viewpoint in case the input is not created yet */
304 if( !b_absolute )
306 p_mi->viewpoint.yaw += update.yaw;
307 p_mi->viewpoint.pitch += update.pitch;
308 p_mi->viewpoint.roll += update.roll;
309 p_mi->viewpoint.fov += update.fov;
311 else
312 p_mi->viewpoint = update;
314 vlc_viewpoint_clip( &p_mi->viewpoint );
316 return 0;
319 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
321 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
323 if( !p_input_thread )
325 libvlc_printerr( "No active input" );
326 return -1;
329 int i_spu = var_GetInteger( p_input_thread, "spu-es" );
330 vlc_object_release( p_input_thread );
331 return i_spu;
334 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
336 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
337 int i_spu_count;
339 if( !p_input_thread )
340 return 0;
342 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
343 vlc_object_release( p_input_thread );
344 return i_spu_count;
347 libvlc_track_description_t *
348 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
350 return libvlc_get_track_description( p_mi, "spu-es" );
353 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
355 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
356 vlc_value_t *list;
357 size_t count;
358 int i_ret = -1;
360 if( !p_input_thread )
361 return -1;
363 var_Change(p_input_thread, "spu-es", VLC_VAR_GETCHOICES,
364 &count, &list, (char ***)NULL);
365 for (size_t i = 0; i < count; i++)
367 if( i_spu == list[i].i_int )
369 if( var_SetInteger( p_input_thread, "spu-es", i_spu ) < 0 )
370 break;
371 i_ret = 0;
372 goto end;
375 libvlc_printerr( "Track identifier not found" );
376 end:
377 vlc_object_release (p_input_thread);
378 free(list);
379 return i_ret;
382 int64_t libvlc_video_get_spu_delay( libvlc_media_player_t *p_mi )
384 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
385 int64_t val = 0;
387 if( p_input_thread )
389 val = US_FROM_VLC_TICK( var_GetInteger( p_input_thread, "spu-delay" ) );
390 vlc_object_release( p_input_thread );
392 else
394 libvlc_printerr( "No active input" );
397 return val;
400 int libvlc_video_set_spu_delay( libvlc_media_player_t *p_mi,
401 int64_t i_delay )
403 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
404 int ret = -1;
406 if( p_input_thread )
408 var_SetInteger( p_input_thread, "spu-delay", VLC_TICK_FROM_US( i_delay ) );
409 vlc_object_release( p_input_thread );
410 ret = 0;
412 else
414 libvlc_printerr( "No active input" );
417 return ret;
420 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
422 return var_GetNonEmptyString (p_mi, "crop");
425 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
426 const char *psz_geometry )
428 if (psz_geometry == NULL)
429 psz_geometry = "";
431 var_SetString (p_mi, "crop", psz_geometry);
433 size_t n;
434 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
436 for (size_t i = 0; i < n; i++)
438 vout_thread_t *p_vout = pp_vouts[i];
440 var_SetString (p_vout, "crop", psz_geometry);
441 vlc_object_release (p_vout);
443 free (pp_vouts);
446 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
448 return var_GetInteger (p_mi, "vbi-page");
451 static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
453 if( b_enable )
455 vlc_value_t *list;
456 size_t count;
458 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
459 &count, &list, (char ***)NULL ) )
461 if( count > 0 )
462 var_SetInteger( p_input_thread, "spu-es", list[0].i_int );
464 free(list);
467 else
468 var_SetInteger( p_input_thread, "spu-es", -1 );
471 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
473 input_thread_t *p_input_thread;
474 vlc_object_t *p_zvbi = NULL;
475 int telx;
476 bool b_key = false;
478 if( i_page >= 0 && i_page < 1000 )
479 var_SetInteger( p_mi, "vbi-page", i_page );
480 else if( i_page >= 1000 )
482 switch (i_page)
484 case libvlc_teletext_key_red:
485 case libvlc_teletext_key_green:
486 case libvlc_teletext_key_yellow:
487 case libvlc_teletext_key_blue:
488 case libvlc_teletext_key_index:
489 b_key = true;
490 break;
491 default:
492 libvlc_printerr("Invalid key action");
493 return;
496 else
498 libvlc_printerr("Invalid page number");
499 return;
502 p_input_thread = libvlc_get_input_thread( p_mi );
503 if( !p_input_thread ) return;
505 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
507 vlc_object_release( p_input_thread );
508 return;
511 if( i_page == 0 )
513 teletext_enable( p_input_thread, false );
515 else
517 telx = var_GetInteger( p_input_thread, "teletext-es" );
518 if( telx >= 0 )
520 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
521 == VLC_SUCCESS )
523 var_SetInteger( p_zvbi, "vbi-page", i_page );
524 vlc_object_release( p_zvbi );
527 else if (!b_key)
529 /* the "vbi-page" will be selected on es creation */
530 teletext_enable( p_input_thread, true );
532 else
533 libvlc_printerr("Key action sent while the teletext is disabled");
535 vlc_object_release( p_input_thread );
538 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
540 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
541 int i_track_count;
543 if( !p_input_thread )
544 return -1;
546 i_track_count = var_CountChoices( p_input_thread, "video-es" );
548 vlc_object_release( p_input_thread );
549 return i_track_count;
552 libvlc_track_description_t *
553 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
555 return libvlc_get_track_description( p_mi, "video-es" );
558 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
560 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
562 if( !p_input_thread )
563 return -1;
565 int id = var_GetInteger( p_input_thread, "video-es" );
566 vlc_object_release( p_input_thread );
567 return id;
570 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
572 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
573 vlc_value_t *val_list;
574 size_t count;
575 int i_ret = -1;
577 if( !p_input_thread )
578 return -1;
580 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES,
581 &count, &val_list, (char ***)NULL );
582 for( size_t i = 0; i < count; i++ )
584 if( i_track == val_list[i].i_int )
586 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
587 break;
588 i_ret = 0;
589 goto end;
592 libvlc_printerr( "Track identifier not found" );
593 end:
594 free(val_list);
595 vlc_object_release( p_input_thread );
596 return i_ret;
599 /******************************************************************************
600 * libvlc_video_set_deinterlace : enable/disable/auto deinterlace and filter
601 *****************************************************************************/
602 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int deinterlace,
603 const char *psz_mode )
605 if (deinterlace != 0 && deinterlace != 1)
606 deinterlace = -1;
608 if (psz_mode
609 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
610 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
611 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
612 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x")
613 && strcmp (psz_mode, "phosphor") && strcmp (psz_mode, "ivtc")
614 && strcmp (psz_mode, "auto"))
615 return;
617 if (psz_mode && deinterlace != 0)
618 var_SetString (p_mi, "deinterlace-mode", psz_mode);
620 var_SetInteger (p_mi, "deinterlace", deinterlace);
622 size_t n;
623 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
624 for (size_t i = 0; i < n; i++)
626 vout_thread_t *p_vout = pp_vouts[i];
628 if (psz_mode && deinterlace != 0)
629 var_SetString (p_vout, "deinterlace-mode", psz_mode);
631 var_SetInteger (p_vout, "deinterlace", deinterlace);
632 vlc_object_release (p_vout);
634 free (pp_vouts);
637 /* ************** */
638 /* module helpers */
639 /* ************** */
641 static int get_filter_str( vlc_object_t *p_parent, const char *psz_name,
642 bool b_add, const char **ppsz_filter_type,
643 char **ppsz_filter_value)
645 char *psz_parser;
646 char *psz_string;
647 const char *psz_filter_type;
649 module_t *p_obj = module_find( psz_name );
650 if( !p_obj )
652 msg_Err( p_parent, "Unable to find filter module \"%s\".", psz_name );
653 return VLC_EGENERIC;
656 if( module_provides( p_obj, "video filter" ) )
658 psz_filter_type = "video-filter";
660 else if( module_provides( p_obj, "sub source" ) )
662 psz_filter_type = "sub-source";
664 else if( module_provides( p_obj, "sub filter" ) )
666 psz_filter_type = "sub-filter";
668 else
670 msg_Err( p_parent, "Unknown video filter type." );
671 return VLC_EGENERIC;
674 psz_string = var_GetString( p_parent, psz_filter_type );
676 /* Todo : Use some generic chain manipulation functions */
677 if( !psz_string ) psz_string = strdup("");
679 psz_parser = strstr( psz_string, psz_name );
680 if( b_add )
682 if( !psz_parser )
684 psz_parser = psz_string;
685 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
686 psz_string, psz_name ) == -1 )
688 free( psz_parser );
689 return VLC_EGENERIC;
691 free( psz_parser );
693 else
695 free( psz_string );
696 return VLC_EGENERIC;
699 else
701 if( psz_parser )
703 memmove( psz_parser, psz_parser + strlen(psz_name) +
704 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
705 strlen(psz_parser + strlen(psz_name)) + 1 );
707 /* Remove trailing : : */
708 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
709 *(psz_string+strlen(psz_string ) -1 ) = '\0';
711 else
713 free( psz_string );
714 return VLC_EGENERIC;
718 *ppsz_filter_type = psz_filter_type;
719 *ppsz_filter_value = psz_string;
720 return VLC_SUCCESS;
723 static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *restrict name )
725 vout_thread_t *vout = GetVout( p_mi, 0 );
726 if (!vout)
727 return false;
729 char *psz_sources = var_GetString( vout, "sub-source" );
730 if( !psz_sources )
732 libvlc_printerr( "%s not enabled", name );
733 vlc_object_release( vout );
734 return false;
737 /* Find 'name' */
738 char *p = strstr( psz_sources, name );
739 free( psz_sources );
740 vlc_object_release( vout );
741 return (p != NULL);
744 typedef const struct {
745 const char name[20];
746 unsigned type;
747 } opt_t;
749 static void
750 set_value( libvlc_media_player_t *p_mi, const char *restrict name,
751 const opt_t *restrict opt, unsigned i_expected_type,
752 const vlc_value_t *val, bool b_sub_source )
754 if( !opt ) return;
756 int i_type = opt->type;
757 vlc_value_t new_val = *val;
758 const char *psz_opt_name = opt->name;
759 switch( i_type )
761 case 0: /* the enabler */
763 int i_ret = get_filter_str( VLC_OBJECT( p_mi ), opt->name, val->i_int,
764 &psz_opt_name, &new_val.psz_string );
765 if( i_ret != VLC_SUCCESS )
766 return;
767 i_type = VLC_VAR_STRING;
768 break;
770 case VLC_VAR_INTEGER:
771 case VLC_VAR_FLOAT:
772 case VLC_VAR_STRING:
773 if( i_expected_type != opt->type )
775 libvlc_printerr( "Invalid argument to %s", name );
776 return;
778 break;
779 default:
780 libvlc_printerr( "Invalid argument to %s", name );
781 return;
784 /* Set the new value to the media player. Next vouts created from this
785 * media player will inherit this new value */
786 var_SetChecked( p_mi, psz_opt_name, i_type, new_val );
788 /* Set the new value to every loaded vouts */
789 size_t i_vout_count;
790 vout_thread_t **pp_vouts = GetVouts( p_mi, &i_vout_count );
791 for( size_t i = 0; i < i_vout_count; ++i )
793 var_SetChecked( pp_vouts[i], psz_opt_name, i_type, new_val );
794 if( b_sub_source )
795 var_TriggerCallback( pp_vouts[i], "sub-source" );
796 vlc_object_release( pp_vouts[i] );
799 if( opt->type == 0 )
800 free( new_val.psz_string );
803 static int
804 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
805 const opt_t *restrict opt )
807 if( !opt ) return 0;
809 switch( opt->type )
811 case 0: /* the enabler */
813 bool b_enabled = find_sub_source_by_name( p_mi, name );
814 return b_enabled ? 1 : 0;
816 case VLC_VAR_INTEGER:
817 return var_GetInteger(p_mi, opt->name);
818 case VLC_VAR_FLOAT:
819 return lroundf(var_GetFloat(p_mi, opt->name));
820 default:
821 libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
822 return 0;
826 static float
827 get_float( libvlc_media_player_t *p_mi, const char *restrict name,
828 const opt_t *restrict opt )
830 if( !opt ) return 0.0;
832 if( opt->type != VLC_VAR_FLOAT )
834 libvlc_printerr( "Invalid argument to %s in %s", name, "get float" );
835 return 0.0;
838 return var_GetFloat( p_mi, opt->name );
841 static char *
842 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
843 const opt_t *restrict opt )
845 if( !opt ) return NULL;
847 if( opt->type != VLC_VAR_STRING )
849 libvlc_printerr( "Invalid argument to %s in %s", name, "get string" );
850 return NULL;
853 return var_GetString( p_mi, opt->name );
856 static const opt_t *
857 marq_option_bynumber(unsigned option)
859 static const opt_t optlist[] =
861 { "marq", 0 },
862 { "marq-marquee", VLC_VAR_STRING },
863 { "marq-color", VLC_VAR_INTEGER },
864 { "marq-opacity", VLC_VAR_INTEGER },
865 { "marq-position", VLC_VAR_INTEGER },
866 { "marq-refresh", VLC_VAR_INTEGER },
867 { "marq-size", VLC_VAR_INTEGER },
868 { "marq-timeout", VLC_VAR_INTEGER },
869 { "marq-x", VLC_VAR_INTEGER },
870 { "marq-y", VLC_VAR_INTEGER },
872 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
874 const opt_t *r = option < num_opts ? optlist+option : NULL;
875 if( !r )
876 libvlc_printerr( "Unknown marquee option" );
877 return r;
880 /*****************************************************************************
881 * libvlc_video_get_marquee_int : get a marq option value
882 *****************************************************************************/
883 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
884 unsigned option )
886 return get_int( p_mi, "marq", marq_option_bynumber(option) );
889 /*****************************************************************************
890 * libvlc_video_get_marquee_string : get a marq option value
891 *****************************************************************************/
892 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
893 unsigned option )
895 return get_string( p_mi, "marq", marq_option_bynumber(option) );
898 /*****************************************************************************
899 * libvlc_video_set_marquee_int: enable, disable or set an int option
900 *****************************************************************************/
901 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
902 unsigned option, int value )
904 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_INTEGER,
905 &(vlc_value_t) { .i_int = value }, true );
908 /*****************************************************************************
909 * libvlc_video_set_marquee_string: set a string option
910 *****************************************************************************/
911 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
912 unsigned option, const char * value )
914 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_STRING,
915 &(vlc_value_t){ .psz_string = (char *)value }, true );
919 /* logo module support */
921 static const opt_t *
922 logo_option_bynumber( unsigned option )
924 static const opt_t vlogo_optlist[] =
925 /* depends on libvlc_video_logo_option_t */
927 { "logo", 0 },
928 { "logo-file", VLC_VAR_STRING },
929 { "logo-x", VLC_VAR_INTEGER },
930 { "logo-y", VLC_VAR_INTEGER },
931 { "logo-delay", VLC_VAR_INTEGER },
932 { "logo-repeat", VLC_VAR_INTEGER },
933 { "logo-opacity", VLC_VAR_INTEGER },
934 { "logo-position", VLC_VAR_INTEGER },
936 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
938 const opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
939 if( !r )
940 libvlc_printerr( "Unknown logo option" );
941 return r;
944 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
945 unsigned option, const char *psz_value )
947 set_value( p_mi,"logo",logo_option_bynumber(option), VLC_VAR_STRING,
948 &(vlc_value_t){ .psz_string = (char *)psz_value }, true );
952 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
953 unsigned option, int value )
955 set_value( p_mi, "logo", logo_option_bynumber(option), VLC_VAR_INTEGER,
956 &(vlc_value_t) { .i_int = value }, true );
960 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
961 unsigned option )
963 return get_int( p_mi, "logo", logo_option_bynumber(option) );
967 /* adjust module support */
970 static const opt_t *
971 adjust_option_bynumber( unsigned option )
973 static const opt_t optlist[] =
975 { "adjust", 0 },
976 { "contrast", VLC_VAR_FLOAT },
977 { "brightness", VLC_VAR_FLOAT },
978 { "hue", VLC_VAR_FLOAT },
979 { "saturation", VLC_VAR_FLOAT },
980 { "gamma", VLC_VAR_FLOAT },
982 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
984 const opt_t *r = option < num_opts ? optlist+option : NULL;
985 if( !r )
986 libvlc_printerr( "Unknown adjust option" );
987 return r;
991 void libvlc_video_set_adjust_int( libvlc_media_player_t *p_mi,
992 unsigned option, int value )
994 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_INTEGER,
995 &(vlc_value_t) { .i_int = value }, false );
999 int libvlc_video_get_adjust_int( libvlc_media_player_t *p_mi,
1000 unsigned option )
1002 return get_int( p_mi, "adjust", adjust_option_bynumber(option) );
1006 void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
1007 unsigned option, float value )
1009 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_FLOAT,
1010 &(vlc_value_t) { .f_float = value }, false );
1014 float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
1015 unsigned option )
1017 return get_float( p_mi, "adjust", adjust_option_bynumber(option) );