use a structure to pass the parameters of player_init(); very useful for future extensions without to break ABI
authorMathieu Schroeter <mathieu.schroeter@mycable.ch>
Fri, 08 Jan 2010 10:28:57 +0100
changeset 1303e3705df5ce2e
parent 1302 8b3bf60ef741
child 1304 453e1b859aa0
use a structure to pass the parameters of player_init(); very useful for future extensions without to break ABI
libplayer-regtest.c
libplayer-test.c
libplayer-testvdr.c
src/player.c
src/player.h
     1.1 --- a/libplayer-regtest.c	Fri Jan 08 10:18:25 2010 +0100
     1.2 +++ b/libplayer-regtest.c	Fri Jan 08 10:28:57 2010 +0100
     1.3 @@ -140,9 +140,14 @@
     1.4  player_run_test (player_type_t player_type)
     1.5  {
     1.6    player_t *player = NULL;
     1.7 +  player_init_param_t param;
     1.8  
     1.9 -  player = player_init (player_type, PLAYER_AO_ALSA, PLAYER_VO_XV,
    1.10 -                        PLAYER_MSG_INFO, 0, frontend_event_cb);
    1.11 +  memset (&param, 0, sizeof (player_init_param_t));
    1.12 +  param.ao       = PLAYER_AO_ALSA;
    1.13 +  param.vo       = PLAYER_VO_XV;
    1.14 +  param.event_cb = frontend_event_cb;
    1.15 +
    1.16 +  player = player_init (player_type, PLAYER_MSG_INFO, &param);
    1.17    do_regression_tests (player, AUDIO_TEST_FILE);
    1.18    do_regression_tests (player, VIDEO_TEST_FILE);
    1.19    player_uninit (player);
     2.1 --- a/libplayer-test.c	Fri Jan 08 10:18:25 2010 +0100
     2.2 +++ b/libplayer-test.c	Fri Jan 08 10:28:57 2010 +0100
     2.3 @@ -802,6 +802,7 @@
     2.4  main (int argc, char **argv)
     2.5  {
     2.6    player_t *player;
     2.7 +  player_init_param_t param;
     2.8    player_type_t type = PLAYER_TYPE_DUMMY;
     2.9    player_vo_t vo = PLAYER_VO_AUTO;
    2.10    player_ao_t ao = PLAYER_AO_AUTO;
    2.11 @@ -921,7 +922,12 @@
    2.12    for (i = 0; i < argc; i++)
    2.13      *(argv_bak + i) = strdup (argv[i]);
    2.14  
    2.15 -  player = player_init (type, ao, vo, verbosity, 0, event_cb);
    2.16 +  memset (&param, 0, sizeof (player_init_param_t));
    2.17 +  param.ao       = ao;
    2.18 +  param.vo       = vo;
    2.19 +  param.event_cb = event_cb;
    2.20 +
    2.21 +  player = player_init (type, verbosity, &param);
    2.22  
    2.23    if (!player)
    2.24      return -1;
     3.1 --- a/libplayer-testvdr.c	Fri Jan 08 10:18:25 2010 +0100
     3.2 +++ b/libplayer-testvdr.c	Fri Jan 08 10:28:57 2010 +0100
     3.3 @@ -91,15 +91,19 @@
     3.4  main (pl_unused int argc, pl_unused char **argv)
     3.5  {
     3.6    player_t *player;
     3.7 +  player_init_param_t param;
     3.8    player_type_t type = PLAYER_TYPE_XINE;
     3.9 -  player_vo_t vo = PLAYER_VO_X11;
    3.10 -  player_ao_t ao = PLAYER_AO_ALSA;
    3.11    player_verbosity_level_t verbosity = PLAYER_MSG_INFO;
    3.12    mrl_t *mrl = NULL;
    3.13    mrl_resource_tv_args_t *args;
    3.14    uint32_t input;
    3.15  
    3.16 -  player = player_init (type, ao, vo, verbosity, 0, event_cb);
    3.17 +  memset (&param, 0, sizeof (player_init_param_t));
    3.18 +  param.ao       = PLAYER_AO_ALSA;
    3.19 +  param.vo       = PLAYER_VO_X11;
    3.20 +  param.event_cb = event_cb;
    3.21 +
    3.22 +  player = player_init (type, verbosity, &param);
    3.23  
    3.24    args = calloc (1, sizeof (mrl_resource_tv_args_t));
    3.25    args->device = strdup ("/tmp/vdr-xine/stream");
     4.1 --- a/src/player.c	Fri Jan 08 10:18:25 2010 +0100
     4.2 +++ b/src/player.c	Fri Jan 08 10:28:57 2010 +0100
     4.3 @@ -96,9 +96,8 @@
     4.4  /***************************************************************************/
     4.5  
     4.6  player_t *
     4.7 -player_init (player_type_t type, player_ao_t ao, player_vo_t vo,
     4.8 -             player_verbosity_level_t verbosity, unsigned long winid,
     4.9 -             int (*event_cb) (player_event_t e, void *data))
    4.10 +player_init (player_type_t type,
    4.11 +             player_verbosity_level_t verbosity, player_init_param_t *param)
    4.12  {
    4.13    player_t *player = NULL;
    4.14    init_status_t res = PLAYER_INIT_ERROR;
    4.15 @@ -117,10 +116,10 @@
    4.16    player->type      = type;
    4.17    player->verbosity = verbosity;
    4.18    player->state     = PLAYER_STATE_IDLE;
    4.19 -  player->ao        = ao;
    4.20 -  player->vo        = vo;
    4.21 -  player->winid     = winid;
    4.22 -  player->event_cb  = event_cb;
    4.23 +  player->ao        = param ? param->ao       : PLAYER_AO_AUTO;
    4.24 +  player->vo        = param ? param->vo       : PLAYER_VO_AUTO;
    4.25 +  player->winid     = param ? param->winid    : 0;
    4.26 +  player->event_cb  = param ? param->event_cb : NULL;
    4.27    player->playlist  = pl_playlist_new (0, 0, PLAYER_LOOP_DISABLE);
    4.28  
    4.29    pthread_mutex_init (&player->mutex_verb, NULL);
     5.1 --- a/src/player.h	Fri Jan 08 10:18:25 2010 +0100
     5.2 +++ b/src/player.h	Fri Jan 08 10:28:57 2010 +0100
     5.3 @@ -154,6 +154,20 @@
     5.4    PLAYER_MSG_CRITICAL,      /* prevents lib from working */
     5.5  } player_verbosity_level_t;
     5.6  
     5.7 +/** \brief Parameters for player_init() .*/
     5.8 +typedef struct player_init_param_s {
     5.9 +  /** Audio output driver. */
    5.10 +  player_ao_t ao;
    5.11 +  /** Video output driver. */
    5.12 +  player_vo_t vo;
    5.13 +  /** Window ID to attach the video (X Window). */
    5.14 +  unsigned long winid;
    5.15 +
    5.16 +  /** Public event callback. */
    5.17 +  int (*event_cb) (player_event_t e, void *data);
    5.18 +
    5.19 +} player_init_param_t;
    5.20 +
    5.21  /**
    5.22   * \name Player (Un)Initialization.
    5.23   * @{
    5.24 @@ -165,21 +179,23 @@
    5.25   * Multiple player controllers can be initialized with any wrappers.
    5.26   * The same Window ID can be used to attach their video.
    5.27   *
    5.28 + * For a description of each parameters supported by this function:
    5.29 + * \see ::player_init_param_t
    5.30 + *
    5.31 + * When a parameter in \p param is 0 (or NULL), its default value is used.
    5.32 + * If \p param is NULL, then all default values are forced for all parameters.
    5.33 + *
    5.34   * Wrappers supported (even partially):
    5.35   *  GStreamer, MPlayer, VLC, xine
    5.36   *
    5.37   * \warning MT-Safe in multithreaded applications (see \ref mtlevel).
    5.38   * \param[in] type        Type of wrapper to load.
    5.39 - * \param[in] ao          Audio output driver to use.
    5.40 - * \param[in] vo          Video output driver to use.
    5.41   * \param[in] verbosity   Level of verbosity to set.
    5.42 - * \param[in] winid       WinID to attach the video (X Window), 0 to disable.
    5.43 - * \param[in] event_cb    Public callback, NULL to disable.
    5.44 + * \param[in] param       Parameters, NULL for default values.
    5.45   * \return Player controller, NULL otherwise.
    5.46   */
    5.47 -player_t *player_init (player_type_t type, player_ao_t ao, player_vo_t vo,
    5.48 -                       player_verbosity_level_t verbosity, unsigned long winid,
    5.49 -                       int (*event_cb) (player_event_t e, void *data));
    5.50 +player_t *player_init (player_type_t type, player_verbosity_level_t verbosity,
    5.51 +                       player_init_param_t *param);
    5.52  
    5.53  /**
    5.54   * \brief Uninitialization of a player controller.