<commit_before>/*
 * GeeXboX libplayer: a multimedia A/V abstraction layer API.
 * Copyright (C) 2006-2008 <NAME> <<EMAIL>>
 * Copyright (C) 2007-2008 <NAME> <<EMAIL>>
 *
 * This file is part of libplayer.
 *
 * libplayer is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with libplayer; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <pthread.h>

#include "player.h"
#include "player_internals.h"
#include "logs.h"
#include "playlist.h" /* pl_playlist_new pl_playlist_free */
#include "supervisor.h"
#include "event_handler.h"

/* players wrappers */
#include "wrapper_dummy.h"
#ifdef HAVE_XINE
#include "wrapper_xine.h"
#endif /* HAVE_XINE */
#ifdef HAVE_MPLAYER
#include "wrapper_mplayer.h"
#endif /* HAVE_MPLAYER */
#ifdef HAVE_VLC
#include "wrapper_vlc.h"
#endif /* HAVE_VLC */
#ifdef HAVE_GSTREAMER
#include "wrapper_gstreamer.h"
#endif /* HAVE_GSTREAMER */

#define MODULE_NAME "player"

static int
player_event_cb (void *data, int e)
{
  int res = 0;
  player_t *player = data;
  player_pb_t pb_mode = PLAYER_PB_SINGLE;

  pl_log (player, PLAYER_MSG_VERBOSE, MODULE_NAME, "internal event: %i", e);

  if (!player)
  {
    pl_event_handler_sync_release (player->event);
    return -1;
  }

  /* send to the frontend event callback */
  if (player->event_cb)
  {
    pl_supervisor_callback_in (player, pthread_self ());
    res = player->event_cb (e, player->user_data);
    pl_supervisor_callback_out (player);
  }

  if (e == PLAYER_EVENT_PLAYBACK_FINISHED)
  {
    player->state = PLAYER_STATE_IDLE;
    pb_mode = player->pb_mode;
  }

  /* release for supervisor */
  pl_event_handler_sync_release (player->event);

  /* go to the next MRL */
  if (pb_mode == PLAYER_PB_AUTO)
    pl_supervisor_send (player, SV_MODE_NO_WAIT,
                        SV_FUNC_PLAYER_MRL_NEXT_PLAY, NULL, NULL);

  return res;
}

/***************************************************************************/
/*                                                                         */
/* Player (Un)Initialization                                               */
/*                                                                         */
/***************************************************************************/

player_t *
player_init (player_type_t type,
             player_verbosity_level_t verbosity, player_init_param_t *param)
{
  player_t *player = NULL;
  init_status_t res = PLAYER_INIT_ERROR;
  supervisor_status_t sv_res;
  int ret;

  int *sv_run;
  pthread_t *sv_job;
  pthread_cond_t *sv_cond;
  pthread_mutex_t *sv_mutex;

  player = calloc (1, sizeof (player_t));
  if (!player)
    return NULL;

  player->type        = type;
  player->verbosity   = verbosity;
  player->state       = PLAYER_STATE_IDLE;
  player->ao          = param ? param->ao       : PLAYER_AO_AUTO;
  player->vo          = param ? param->vo       : PLAYER_VO_AUTO;
  player->winid       = param ? param->winid    : 0;
  player->x11_display = param ? param->display  : NULL;
  player->event_cb    = param ? param->event_cb : NULL;
  player->user_data   = param ? param->data     : NULL;
  player->playlist    = pl_playlist_new (0, 0, PLAYER_LOOP_DISABLE);

  pthread_mutex_init (&player->mutex_verb, NULL);

  switch (player->type)
  {<commit_msg>factorize the test on param; the default values are set by calloc()<commit_after>/*
 * GeeXboX libplayer: a multimedia A/V abstraction layer API.
 * Copyright (C) 2006-2008 <NAME> <<EMAIL>>
 * Copyright (C) 2007-2008 <NAME> <<EMAIL>>
 *
 * This file is part of libplayer.
 *
 * libplayer is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with libplayer; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <pthread.h>

#include "player.h"
#include "player_internals.h"
#include "logs.h"
#include "playlist.h" /* pl_playlist_new pl_playlist_free */
#include "supervisor.h"
#include "event_handler.h"

/* players wrappers */
#include "wrapper_dummy.h"
#ifdef HAVE_XINE
#include "wrapper_xine.h"
#endif /* HAVE_XINE */
#ifdef HAVE_MPLAYER
#include "wrapper_mplayer.h"
#endif /* HAVE_MPLAYER */
#ifdef HAVE_VLC
#include "wrapper_vlc.h"
#endif /* HAVE_VLC */
#ifdef HAVE_GSTREAMER
#include "wrapper_gstreamer.h"
#endif /* HAVE_GSTREAMER */

#define MODULE_NAME "player"

static int
player_event_cb (void *data, int e)
{
  int res = 0;
  player_t *player = data;
  player_pb_t pb_mode = PLAYER_PB_SINGLE;

  pl_log (player, PLAYER_MSG_VERBOSE, MODULE_NAME, "internal event: %i", e);

  if (!player)
  {
    pl_event_handler_sync_release (player->event);
    return -1;
  }

  /* send to the frontend event callback */
  if (player->event_cb)
  {
    pl_supervisor_callback_in (player, pthread_self ());
    res = player->event_cb (e, player->user_data);
    pl_supervisor_callback_out (player);
  }

  if (e == PLAYER_EVENT_PLAYBACK_FINISHED)
  {
    player->state = PLAYER_STATE_IDLE;
    pb_mode = player->pb_mode;
  }

  /* release for supervisor */
  pl_event_handler_sync_release (player->event);

  /* go to the next MRL */
  if (pb_mode == PLAYER_PB_AUTO)
    pl_supervisor_send (player, SV_MODE_NO_WAIT,
                        SV_FUNC_PLAYER_MRL_NEXT_PLAY, NULL, NULL);

  return res;
}

/***************************************************************************/
/*                                                                         */
/* Player (Un)Initialization                                               */
/*                                                                         */
/***************************************************************************/

player_t *
player_init (player_type_t type,
             player_verbosity_level_t verbosity, player_init_param_t *param)
{
  player_t *player = NULL;
  init_status_t res = PLAYER_INIT_ERROR;
  supervisor_status_t sv_res;
  int ret;

  int *sv_run;
  pthread_t *sv_job;
  pthread_cond_t *sv_cond;
  pthread_mutex_t *sv_mutex;

  player = calloc (1, sizeof (player_t));
  if (!player)
    return NULL;

  player->type        = type;
  player->verbosity   = verbosity;
  player->state       = PLAYER_STATE_IDLE;
  player->playlist    = pl_playlist_new (0, 0, PLAYER_LOOP_DISABLE);

  if (param)
  {
    player->ao          = param->ao;
    player->vo          = param->vo;
    player->winid       = param->winid;
    player->x11_display = param->display;
    player->event_cb    = param->event_cb;
    player->user_data   = param->data;
  }

  pthread_mutex_init (&player->mutex_verb, NULL);

  switch (player->type)
  {
{'fraction_non_alphanumeric': 0.14010530371131372, 'fraction_numerical': 0.009374598690124566, 'mean_word_length': 3.0331434489901605, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1399520', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2432, 'n_words': 687}