demux: ogg: check first frame granule index
[vlc.git] / lib / video.c
blobf3445f351bccca1eae1fc9e4520b7f438bb82e4e
1 /*****************************************************************************
2 * video.c: libvlc new API video functions
3 *****************************************************************************
4 * Copyright (C) 2005-2010 VLC authors and VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Filippo Carone <littlejohn@videolan.org>
9 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
10 * Damien Fouilleul <damienf a_t videolan dot org>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc/libvlc.h>
32 #include <vlc/libvlc_renderer_discoverer.h>
33 #include <vlc/libvlc_picture.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>
41 #include <vlc_url.h>
43 #include "libvlc_internal.h"
44 #include "media_player_internal.h"
45 #include <math.h>
46 #include <assert.h>
49 * Remember to release the returned vout_thread_t.
51 static vout_thread_t **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
53 input_thread_t *p_input = libvlc_get_input_thread( p_mi );
54 if( !p_input )
56 *n = 0;
57 return NULL;
60 vout_thread_t **pp_vouts;
61 if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
63 *n = 0;
64 pp_vouts = NULL;
66 vlc_object_release (p_input);
67 return pp_vouts;
70 static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
72 vout_thread_t *p_vout = NULL;
73 size_t n;
74 vout_thread_t **pp_vouts = GetVouts (mp, &n);
75 if (pp_vouts == NULL)
76 goto err;
78 if (num < n)
79 p_vout = pp_vouts[num];
81 for (size_t i = 0; i < n; i++)
82 if (i != num)
83 vlc_object_release (pp_vouts[i]);
84 free (pp_vouts);
86 if (p_vout == NULL)
87 err:
88 libvlc_printerr ("Video output not active");
89 return p_vout;
92 /**********************************************************************
93 * Exported functions
94 **********************************************************************/
96 void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
98 /* This will work even if the video is not currently active */
99 var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
101 /* Apply to current video outputs (if any) */
102 size_t n;
103 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
104 for (size_t i = 0; i < n; i++)
106 var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
107 vlc_object_release (pp_vouts[i]);
109 free (pp_vouts);
112 int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
114 return var_GetBool (p_mi, "fullscreen");
117 void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
119 bool b_fullscreen = var_ToggleBool (p_mi, "fullscreen");
121 /* Apply to current video outputs (if any) */
122 size_t n;
123 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
124 for (size_t i = 0; i < n; i++)
126 vout_thread_t *p_vout = pp_vouts[i];
128 var_SetBool (p_vout, "fullscreen", b_fullscreen);
129 vlc_object_release (p_vout);
131 free (pp_vouts);
134 void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
136 var_SetBool (p_mi, "keyboard-events", !!on);
139 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
141 var_SetBool (p_mi, "mouse-events", !!on);
145 libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
146 const char *psz_filepath,
147 unsigned int i_width, unsigned int i_height )
149 assert( psz_filepath );
151 vout_thread_t *p_vout = GetVout (p_mi, num);
152 if (p_vout == NULL)
153 return -1;
155 /* FIXME: This is not atomic. All parameters should be passed at once
156 * (obviously _not_ with var_*()). Also, the libvlc object should not be
157 * used for the callbacks: that breaks badly if there are concurrent
158 * media players in the instance. */
159 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER );
160 var_SetInteger( p_vout, "snapshot-width", i_width);
161 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER );
162 var_SetInteger( p_vout, "snapshot-height", i_height );
163 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING );
164 var_SetString( p_vout, "snapshot-path", psz_filepath );
165 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING );
166 var_SetString( p_vout, "snapshot-format", "png" );
167 var_TriggerCallback( p_vout, "video-snapshot" );
168 vlc_object_release( p_vout );
169 return 0;
172 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
173 unsigned *restrict px, unsigned *restrict py )
175 if (p_mi->p_md == NULL)
176 return -1;
178 libvlc_media_track_t **tracks;
179 unsigned count = libvlc_media_tracks_get(p_mi->p_md, &tracks);
180 int ret = -1;
182 for (unsigned i = 0; i < count; i++)
183 if (tracks[i]->i_type == libvlc_track_video && num-- == 0) {
184 *px = tracks[i]->video->i_width;
185 *py = tracks[i]->video->i_height;
186 ret = 0;
187 break;
190 libvlc_media_tracks_release(tracks, count);
191 return ret;
194 int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
195 int *restrict px, int *restrict py )
197 vout_thread_t *p_vout = GetVout (mp, num);
198 if (p_vout == NULL)
199 return -1;
201 var_GetCoords (p_vout, "mouse-moved", px, py);
202 vlc_object_release (p_vout);
203 return 0;
206 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
208 size_t n;
209 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
210 for (size_t i = 0; i < n; i++)
211 vlc_object_release (pp_vouts[i]);
212 free (pp_vouts);
213 return n;
216 float libvlc_video_get_scale( libvlc_media_player_t *mp )
218 float f_scale = var_GetFloat (mp, "zoom");
219 if (var_GetBool (mp, "autoscale"))
220 f_scale = 0.f;
221 return f_scale;
224 void libvlc_video_set_scale( libvlc_media_player_t *p_mp, float f_scale )
226 if (isfinite(f_scale) && f_scale != 0.f)
227 var_SetFloat (p_mp, "zoom", f_scale);
228 var_SetBool (p_mp, "autoscale", f_scale == 0.f);
230 /* Apply to current video outputs (if any) */
231 size_t n;
232 vout_thread_t **pp_vouts = GetVouts (p_mp, &n);
233 for (size_t i = 0; i < n; i++)
235 vout_thread_t *p_vout = pp_vouts[i];
237 if (isfinite(f_scale) && f_scale != 0.f)
238 var_SetFloat (p_vout, "zoom", f_scale);
239 var_SetBool (p_vout, "autoscale", f_scale == 0.f);
240 vlc_object_release (p_vout);
242 free (pp_vouts);
245 char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *p_mi )
247 return var_GetNonEmptyString (p_mi, "aspect-ratio");
250 void libvlc_video_set_aspect_ratio( libvlc_media_player_t *p_mi,
251 const char *psz_aspect )
253 if (psz_aspect == NULL)
254 psz_aspect = "";
255 var_SetString (p_mi, "aspect-ratio", psz_aspect);
257 size_t n;
258 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
259 for (size_t i = 0; i < n; i++)
261 vout_thread_t *p_vout = pp_vouts[i];
263 var_SetString (p_vout, "aspect-ratio", psz_aspect);
264 vlc_object_release (p_vout);
266 free (pp_vouts);
269 libvlc_video_viewpoint_t *libvlc_video_new_viewpoint(void)
271 libvlc_video_viewpoint_t *p_vp = malloc(sizeof *p_vp);
272 if (unlikely(p_vp == NULL))
273 return NULL;
274 p_vp->f_yaw = p_vp->f_pitch = p_vp->f_roll = p_vp->f_field_of_view = 0.0f;
275 return p_vp;
278 int libvlc_video_update_viewpoint( libvlc_media_player_t *p_mi,
279 const libvlc_video_viewpoint_t *p_viewpoint,
280 bool b_absolute )
282 vlc_viewpoint_t update = {
283 .yaw = p_viewpoint->f_yaw,
284 .pitch = p_viewpoint->f_pitch,
285 .roll = p_viewpoint->f_roll,
286 .fov = p_viewpoint->f_field_of_view,
289 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
290 if( p_input_thread != NULL )
292 if( input_UpdateViewpoint( p_input_thread, &update,
293 b_absolute ) != VLC_SUCCESS )
295 vlc_object_release( p_input_thread );
296 return -1;
298 vlc_object_release( p_input_thread );
299 return 0;
302 /* Save the viewpoint in case the input is not created yet */
303 if( !b_absolute )
305 p_mi->viewpoint.yaw += update.yaw;
306 p_mi->viewpoint.pitch += update.pitch;
307 p_mi->viewpoint.roll += update.roll;
308 p_mi->viewpoint.fov += update.fov;
310 else
311 p_mi->viewpoint = update;
313 vlc_viewpoint_clip( &p_mi->viewpoint );
315 return 0;
318 int libvlc_video_get_spu( libvlc_media_player_t *p_mi )
320 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
322 if( !p_input_thread )
324 libvlc_printerr( "No active input" );
325 return -1;
328 int i_spu = var_GetInteger( p_input_thread, "spu-es" );
329 vlc_object_release( p_input_thread );
330 return i_spu;
333 int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi )
335 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
336 int i_spu_count;
338 if( !p_input_thread )
339 return 0;
341 i_spu_count = var_CountChoices( p_input_thread, "spu-es" );
342 vlc_object_release( p_input_thread );
343 return i_spu_count;
346 libvlc_track_description_t *
347 libvlc_video_get_spu_description( libvlc_media_player_t *p_mi )
349 return libvlc_get_track_description( p_mi, "spu-es" );
352 int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
354 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
355 vlc_value_t *list;
356 size_t count;
357 int i_ret = -1;
359 if( !p_input_thread )
360 return -1;
362 var_Change(p_input_thread, "spu-es", VLC_VAR_GETCHOICES,
363 &count, &list, (char ***)NULL);
364 for (size_t i = 0; i < count; i++)
366 if( i_spu == list[i].i_int )
368 if( var_SetInteger( p_input_thread, "spu-es", i_spu ) < 0 )
369 break;
370 i_ret = 0;
371 goto end;
374 libvlc_printerr( "Track identifier not found" );
375 end:
376 vlc_object_release (p_input_thread);
377 free(list);
378 return i_ret;
381 int64_t libvlc_video_get_spu_delay( libvlc_media_player_t *p_mi )
383 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
384 int64_t val = 0;
386 if( p_input_thread )
388 val = US_FROM_VLC_TICK( var_GetInteger( p_input_thread, "spu-delay" ) );
389 vlc_object_release( p_input_thread );
391 else
393 libvlc_printerr( "No active input" );
396 return val;
399 int libvlc_video_set_spu_delay( libvlc_media_player_t *p_mi,
400 int64_t i_delay )
402 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
403 int ret = -1;
405 if( p_input_thread )
407 var_SetInteger( p_input_thread, "spu-delay", VLC_TICK_FROM_US( i_delay ) );
408 vlc_object_release( p_input_thread );
409 ret = 0;
411 else
413 libvlc_printerr( "No active input" );
416 return ret;
419 char *libvlc_video_get_crop_geometry (libvlc_media_player_t *p_mi)
421 return var_GetNonEmptyString (p_mi, "crop");
424 void libvlc_video_set_crop_geometry( libvlc_media_player_t *p_mi,
425 const char *psz_geometry )
427 if (psz_geometry == NULL)
428 psz_geometry = "";
430 var_SetString (p_mi, "crop", psz_geometry);
432 size_t n;
433 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
435 for (size_t i = 0; i < n; i++)
437 vout_thread_t *p_vout = pp_vouts[i];
439 var_SetString (p_vout, "crop", psz_geometry);
440 vlc_object_release (p_vout);
442 free (pp_vouts);
445 int libvlc_video_get_teletext( libvlc_media_player_t *p_mi )
447 return var_GetInteger (p_mi, "vbi-page");
450 static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
452 if( b_enable )
454 vlc_value_t *list;
455 size_t count;
457 if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
458 &count, &list, (char ***)NULL ) )
460 if( count > 0 )
461 var_SetInteger( p_input_thread, "spu-es", list[0].i_int );
463 free(list);
466 else
467 var_SetInteger( p_input_thread, "spu-es", -1 );
470 void libvlc_video_set_teletext( libvlc_media_player_t *p_mi, int i_page )
472 input_thread_t *p_input_thread;
473 vlc_object_t *p_zvbi = NULL;
474 int telx;
475 bool b_key = false;
477 if( i_page >= 0 && i_page < 1000 )
478 var_SetInteger( p_mi, "vbi-page", i_page );
479 else if( i_page >= 1000 )
481 switch (i_page)
483 case libvlc_teletext_key_red:
484 case libvlc_teletext_key_green:
485 case libvlc_teletext_key_yellow:
486 case libvlc_teletext_key_blue:
487 case libvlc_teletext_key_index:
488 b_key = true;
489 break;
490 default:
491 libvlc_printerr("Invalid key action");
492 return;
495 else
497 libvlc_printerr("Invalid page number");
498 return;
501 p_input_thread = libvlc_get_input_thread( p_mi );
502 if( !p_input_thread ) return;
504 if( var_CountChoices( p_input_thread, "teletext-es" ) <= 0 )
506 vlc_object_release( p_input_thread );
507 return;
510 if( i_page == 0 )
512 teletext_enable( p_input_thread, false );
514 else
516 telx = var_GetInteger( p_input_thread, "teletext-es" );
517 if( telx >= 0 )
519 if( input_GetEsObjects( p_input_thread, telx, &p_zvbi, NULL, NULL )
520 == VLC_SUCCESS )
522 var_SetInteger( p_zvbi, "vbi-page", i_page );
523 vlc_object_release( p_zvbi );
526 else if (!b_key)
528 /* the "vbi-page" will be selected on es creation */
529 teletext_enable( p_input_thread, true );
531 else
532 libvlc_printerr("Key action sent while the teletext is disabled");
534 vlc_object_release( p_input_thread );
537 int libvlc_video_get_track_count( libvlc_media_player_t *p_mi )
539 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
540 int i_track_count;
542 if( !p_input_thread )
543 return -1;
545 i_track_count = var_CountChoices( p_input_thread, "video-es" );
547 vlc_object_release( p_input_thread );
548 return i_track_count;
551 libvlc_track_description_t *
552 libvlc_video_get_track_description( libvlc_media_player_t *p_mi )
554 return libvlc_get_track_description( p_mi, "video-es" );
557 int libvlc_video_get_track( libvlc_media_player_t *p_mi )
559 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
561 if( !p_input_thread )
562 return -1;
564 int id = var_GetInteger( p_input_thread, "video-es" );
565 vlc_object_release( p_input_thread );
566 return id;
569 int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
571 input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
572 vlc_value_t *val_list;
573 size_t count;
574 int i_ret = -1;
576 if( !p_input_thread )
577 return -1;
579 var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES,
580 &count, &val_list, (char ***)NULL );
581 for( size_t i = 0; i < count; i++ )
583 if( i_track == val_list[i].i_int )
585 if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
586 break;
587 i_ret = 0;
588 goto end;
591 libvlc_printerr( "Track identifier not found" );
592 end:
593 free(val_list);
594 vlc_object_release( p_input_thread );
595 return i_ret;
598 /******************************************************************************
599 * libvlc_video_set_deinterlace : enable/disable/auto deinterlace and filter
600 *****************************************************************************/
601 void libvlc_video_set_deinterlace( libvlc_media_player_t *p_mi, int deinterlace,
602 const char *psz_mode )
604 if (deinterlace != 0 && deinterlace != 1)
605 deinterlace = -1;
607 if (psz_mode
608 && strcmp (psz_mode, "blend") && strcmp (psz_mode, "bob")
609 && strcmp (psz_mode, "discard") && strcmp (psz_mode, "linear")
610 && strcmp (psz_mode, "mean") && strcmp (psz_mode, "x")
611 && strcmp (psz_mode, "yadif") && strcmp (psz_mode, "yadif2x")
612 && strcmp (psz_mode, "phosphor") && strcmp (psz_mode, "ivtc")
613 && strcmp (psz_mode, "auto"))
614 return;
616 if (psz_mode && deinterlace != 0)
617 var_SetString (p_mi, "deinterlace-mode", psz_mode);
619 var_SetInteger (p_mi, "deinterlace", deinterlace);
621 size_t n;
622 vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
623 for (size_t i = 0; i < n; i++)
625 vout_thread_t *p_vout = pp_vouts[i];
627 if (psz_mode && deinterlace != 0)
628 var_SetString (p_vout, "deinterlace-mode", psz_mode);
630 var_SetInteger (p_vout, "deinterlace", deinterlace);
631 vlc_object_release (p_vout);
633 free (pp_vouts);
636 /* ************** */
637 /* module helpers */
638 /* ************** */
640 static int get_filter_str( vlc_object_t *p_parent, const char *psz_name,
641 bool b_add, const char **ppsz_filter_type,
642 char **ppsz_filter_value)
644 char *psz_parser;
645 char *psz_string;
646 const char *psz_filter_type;
648 module_t *p_obj = module_find( psz_name );
649 if( !p_obj )
651 msg_Err( p_parent, "Unable to find filter module \"%s\".", psz_name );
652 return VLC_EGENERIC;
655 if( module_provides( p_obj, "video filter" ) )
657 psz_filter_type = "video-filter";
659 else if( module_provides( p_obj, "sub source" ) )
661 psz_filter_type = "sub-source";
663 else if( module_provides( p_obj, "sub filter" ) )
665 psz_filter_type = "sub-filter";
667 else
669 msg_Err( p_parent, "Unknown video filter type." );
670 return VLC_EGENERIC;
673 psz_string = var_GetString( p_parent, psz_filter_type );
675 /* Todo : Use some generic chain manipulation functions */
676 if( !psz_string ) psz_string = strdup("");
678 psz_parser = strstr( psz_string, psz_name );
679 if( b_add )
681 if( !psz_parser )
683 psz_parser = psz_string;
684 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
685 psz_string, psz_name ) == -1 )
687 free( psz_parser );
688 return VLC_EGENERIC;
690 free( psz_parser );
692 else
694 free( psz_string );
695 return VLC_EGENERIC;
698 else
700 if( psz_parser )
702 memmove( psz_parser, psz_parser + strlen(psz_name) +
703 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
704 strlen(psz_parser + strlen(psz_name)) + 1 );
706 /* Remove trailing : : */
707 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
708 *(psz_string+strlen(psz_string ) -1 ) = '\0';
710 else
712 free( psz_string );
713 return VLC_EGENERIC;
717 *ppsz_filter_type = psz_filter_type;
718 *ppsz_filter_value = psz_string;
719 return VLC_SUCCESS;
722 static bool find_sub_source_by_name( libvlc_media_player_t *p_mi, const char *restrict name )
724 vout_thread_t *vout = GetVout( p_mi, 0 );
725 if (!vout)
726 return false;
728 char *psz_sources = var_GetString( vout, "sub-source" );
729 if( !psz_sources )
731 libvlc_printerr( "%s not enabled", name );
732 vlc_object_release( vout );
733 return false;
736 /* Find 'name' */
737 char *p = strstr( psz_sources, name );
738 free( psz_sources );
739 vlc_object_release( vout );
740 return (p != NULL);
743 typedef const struct {
744 const char name[20];
745 unsigned type;
746 } opt_t;
748 static void
749 set_value( libvlc_media_player_t *p_mi, const char *restrict name,
750 const opt_t *restrict opt, unsigned i_expected_type,
751 const vlc_value_t *val, bool b_sub_source )
753 if( !opt ) return;
755 int i_type = opt->type;
756 vlc_value_t new_val = *val;
757 const char *psz_opt_name = opt->name;
758 switch( i_type )
760 case 0: /* the enabler */
762 int i_ret = get_filter_str( VLC_OBJECT( p_mi ), opt->name, val->i_int,
763 &psz_opt_name, &new_val.psz_string );
764 if( i_ret != VLC_SUCCESS )
765 return;
766 i_type = VLC_VAR_STRING;
767 break;
769 case VLC_VAR_INTEGER:
770 case VLC_VAR_FLOAT:
771 case VLC_VAR_STRING:
772 if( i_expected_type != opt->type )
774 libvlc_printerr( "Invalid argument to %s", name );
775 return;
777 break;
778 default:
779 libvlc_printerr( "Invalid argument to %s", name );
780 return;
783 /* Set the new value to the media player. Next vouts created from this
784 * media player will inherit this new value */
785 var_SetChecked( p_mi, psz_opt_name, i_type, new_val );
787 /* Set the new value to every loaded vouts */
788 size_t i_vout_count;
789 vout_thread_t **pp_vouts = GetVouts( p_mi, &i_vout_count );
790 for( size_t i = 0; i < i_vout_count; ++i )
792 var_SetChecked( pp_vouts[i], psz_opt_name, i_type, new_val );
793 if( b_sub_source )
794 var_TriggerCallback( pp_vouts[i], "sub-source" );
795 vlc_object_release( pp_vouts[i] );
798 if( opt->type == 0 )
799 free( new_val.psz_string );
802 static int
803 get_int( libvlc_media_player_t *p_mi, const char *restrict name,
804 const opt_t *restrict opt )
806 if( !opt ) return 0;
808 switch( opt->type )
810 case 0: /* the enabler */
812 bool b_enabled = find_sub_source_by_name( p_mi, name );
813 return b_enabled ? 1 : 0;
815 case VLC_VAR_INTEGER:
816 return var_GetInteger(p_mi, opt->name);
817 case VLC_VAR_FLOAT:
818 return lroundf(var_GetFloat(p_mi, opt->name));
819 default:
820 libvlc_printerr( "Invalid argument to %s in %s", name, "get int" );
821 return 0;
825 static float
826 get_float( libvlc_media_player_t *p_mi, const char *restrict name,
827 const opt_t *restrict opt )
829 if( !opt ) return 0.0;
831 if( opt->type != VLC_VAR_FLOAT )
833 libvlc_printerr( "Invalid argument to %s in %s", name, "get float" );
834 return 0.0;
837 return var_GetFloat( p_mi, opt->name );
840 static char *
841 get_string( libvlc_media_player_t *p_mi, const char *restrict name,
842 const opt_t *restrict opt )
844 if( !opt ) return NULL;
846 if( opt->type != VLC_VAR_STRING )
848 libvlc_printerr( "Invalid argument to %s in %s", name, "get string" );
849 return NULL;
852 return var_GetString( p_mi, opt->name );
855 static const opt_t *
856 marq_option_bynumber(unsigned option)
858 static const opt_t optlist[] =
860 { "marq", 0 },
861 { "marq-marquee", VLC_VAR_STRING },
862 { "marq-color", VLC_VAR_INTEGER },
863 { "marq-opacity", VLC_VAR_INTEGER },
864 { "marq-position", VLC_VAR_INTEGER },
865 { "marq-refresh", VLC_VAR_INTEGER },
866 { "marq-size", VLC_VAR_INTEGER },
867 { "marq-timeout", VLC_VAR_INTEGER },
868 { "marq-x", VLC_VAR_INTEGER },
869 { "marq-y", VLC_VAR_INTEGER },
871 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
873 const opt_t *r = option < num_opts ? optlist+option : NULL;
874 if( !r )
875 libvlc_printerr( "Unknown marquee option" );
876 return r;
879 /*****************************************************************************
880 * libvlc_video_get_marquee_int : get a marq option value
881 *****************************************************************************/
882 int libvlc_video_get_marquee_int( libvlc_media_player_t *p_mi,
883 unsigned option )
885 return get_int( p_mi, "marq", marq_option_bynumber(option) );
888 /*****************************************************************************
889 * libvlc_video_get_marquee_string : get a marq option value
890 *****************************************************************************/
891 char * libvlc_video_get_marquee_string( libvlc_media_player_t *p_mi,
892 unsigned option )
894 return get_string( p_mi, "marq", marq_option_bynumber(option) );
897 /*****************************************************************************
898 * libvlc_video_set_marquee_int: enable, disable or set an int option
899 *****************************************************************************/
900 void libvlc_video_set_marquee_int( libvlc_media_player_t *p_mi,
901 unsigned option, int value )
903 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_INTEGER,
904 &(vlc_value_t) { .i_int = value }, true );
907 /*****************************************************************************
908 * libvlc_video_set_marquee_string: set a string option
909 *****************************************************************************/
910 void libvlc_video_set_marquee_string( libvlc_media_player_t *p_mi,
911 unsigned option, const char * value )
913 set_value( p_mi, "marq", marq_option_bynumber(option), VLC_VAR_STRING,
914 &(vlc_value_t){ .psz_string = (char *)value }, true );
918 /* logo module support */
920 static const opt_t *
921 logo_option_bynumber( unsigned option )
923 static const opt_t vlogo_optlist[] =
924 /* depends on libvlc_video_logo_option_t */
926 { "logo", 0 },
927 { "logo-file", VLC_VAR_STRING },
928 { "logo-x", VLC_VAR_INTEGER },
929 { "logo-y", VLC_VAR_INTEGER },
930 { "logo-delay", VLC_VAR_INTEGER },
931 { "logo-repeat", VLC_VAR_INTEGER },
932 { "logo-opacity", VLC_VAR_INTEGER },
933 { "logo-position", VLC_VAR_INTEGER },
935 enum { num_vlogo_opts = sizeof(vlogo_optlist) / sizeof(*vlogo_optlist) };
937 const opt_t *r = option < num_vlogo_opts ? vlogo_optlist+option : NULL;
938 if( !r )
939 libvlc_printerr( "Unknown logo option" );
940 return r;
943 void libvlc_video_set_logo_string( libvlc_media_player_t *p_mi,
944 unsigned option, const char *psz_value )
946 set_value( p_mi,"logo",logo_option_bynumber(option), VLC_VAR_STRING,
947 &(vlc_value_t){ .psz_string = (char *)psz_value }, true );
951 void libvlc_video_set_logo_int( libvlc_media_player_t *p_mi,
952 unsigned option, int value )
954 set_value( p_mi, "logo", logo_option_bynumber(option), VLC_VAR_INTEGER,
955 &(vlc_value_t) { .i_int = value }, true );
959 int libvlc_video_get_logo_int( libvlc_media_player_t *p_mi,
960 unsigned option )
962 return get_int( p_mi, "logo", logo_option_bynumber(option) );
966 /* adjust module support */
969 static const opt_t *
970 adjust_option_bynumber( unsigned option )
972 static const opt_t optlist[] =
974 { "adjust", 0 },
975 { "contrast", VLC_VAR_FLOAT },
976 { "brightness", VLC_VAR_FLOAT },
977 { "hue", VLC_VAR_FLOAT },
978 { "saturation", VLC_VAR_FLOAT },
979 { "gamma", VLC_VAR_FLOAT },
981 enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
983 const opt_t *r = option < num_opts ? optlist+option : NULL;
984 if( !r )
985 libvlc_printerr( "Unknown adjust option" );
986 return r;
990 void libvlc_video_set_adjust_int( libvlc_media_player_t *p_mi,
991 unsigned option, int value )
993 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_INTEGER,
994 &(vlc_value_t) { .i_int = value }, false );
998 int libvlc_video_get_adjust_int( libvlc_media_player_t *p_mi,
999 unsigned option )
1001 return get_int( p_mi, "adjust", adjust_option_bynumber(option) );
1005 void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
1006 unsigned option, float value )
1008 set_value( p_mi, "adjust", adjust_option_bynumber(option), VLC_VAR_FLOAT,
1009 &(vlc_value_t) { .f_float = value }, false );
1013 float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
1014 unsigned option )
1016 return get_float( p_mi, "adjust", adjust_option_bynumber(option) );