xine-lib: xine-lib-1.2.12/src/xine-engine/metronom.c File Reference

xine-lib 1.2.12

Data Structures | Macros | Functions
metronom.c File Reference
`#include <time.h>`
`#include <inttypes.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <math.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <pthread.h>`
`#include <sys/time.h>`
`#include <xine/xine_internal.h>`
`#include <xine/metronom.h>`
`#include <xine/xineutils.h>`
`#include "xine_private.h"`

## Data Structures
struct | unixscr_values_t
struct | unixscr_t
struct | metronom_clock_private_t
struct | metronom_impl_t

## Macros
#define | LOG_MODULE "metronom"
#define | LOG_VERBOSE
#define | METRONOM_CLOCK_INTERNAL
#define | AUDIO_SAMPLE_LD 15
#define | AUDIO_SAMPLE_NUM (1 << AUDIO_SAMPLE_LD)
#define | AUDIO_SAMPLE_MASK (AUDIO_SAMPLE_NUM - 1)
#define | MAX_SCR_PROVIDERS 10
#define | MAX_SPEED_CHANGE_CALLBACKS 16
#define | VIDEO_DRIFT_TOLERANCE 45000
#define | AUDIO_DRIFT_TOLERANCE 45000
#define | VIDEO_PREDICTION_MODE 0 /* use pts + frame duration */
#define | VIDEO_PTS_MODE 1 /* use only pts */
#define | abs(x) ( ((x)<0) ? -(x) : (x) )
#define | START_PTS 0
#define | STOP_PTS ~0
#define | MASK_PTS (1 << 19) /* 5.825 s */
#define | BOUNCE_MAX 360000

## Functions
static int | unixscr_get_priority (scr_plugin_t *scr)
static void | unixscr_set_pivot (unixscr_t *this)
static int | unixscr_set_speed (scr_plugin_t *scr, int speed)
static void | unixscr_adjust (scr_plugin_t *scr, int64_t vpts)
static void | unixscr_start (scr_plugin_t *scr, int64_t start_vpts)
static int64_t | unixscr_get_current (scr_plugin_t *scr)
static void | unixscr_exit (scr_plugin_t *scr)
static scr_plugin_t * | unixscr_init (void *this_gen)
static void | metronom_register_speed_change_callback (metronom_clock_t *this, xine_speed_change_cb_t *callback, void *user_data)
static void | metronom_unregister_speed_change_callback (metronom_clock_t *this, xine_speed_change_cb_t *callback, void *user_data)
static void | metronom_start_clock (metronom_clock_t *this, int64_t pts)
static int64_t | metronom_get_current_time (metronom_clock_t *this)
static void | metronom_stop_clock (metronom_clock_t *this)
static void | metronom_resume_clock (metronom_clock_t *this)
static void | metronom_adjust_clock (metronom_clock_t *this, int64_t desired_pts)
static int | metronom_set_speed (metronom_clock_t *this, int speed)
static void | metronom_vdr_hack_disc (metronom_impl_t *this, int64_t pts_offs)
static void | metronom_vdr_hack_prebuffer (metronom_impl_t *this, int64_t pts)
static void | metronom_set_audio_rate (metronom_t *this_gen, int64_t pts_per_smpls)
static int64_t | metronom_got_spu_packet (metronom_t *this_gen, int64_t pts)
static int | metronom_handle_discontinuity (metronom_impl_t *this, int type, int try, int64_t disc_off)
static void | metronom_handle_vdr_trick_pts (metronom_impl_t *this, int64_t pts)
static void | metronom_handle_video_discontinuity (metronom_t *this_gen, int type, int64_t disc_off)
static void | metronom_got_video_frame (metronom_t *this_gen, vo_frame_t *img)
static void | metronom_handle_audio_discontinuity (metronom_t *this_gen, int type, int64_t disc_off)
static int64_t | metronom_got_audio_samples (metronom_t *this_gen, int64_t pts, int nsamples)
static void | metronom_set_option (metronom_t *this_gen, int option, int64_t value)
static void | metronom_clock_set_option (metronom_clock_t *this, int option, int64_t value)
static int64_t | metronom_get_option (metronom_t *this_gen, int option)
static int64_t | metronom_clock_get_option (metronom_clock_t *this, int option)
static void | metronom_set_master (metronom_t *this_gen, metronom_t *master)
static scr_plugin_t * | get_master_scr (metronom_clock_t *this)
static void * | metronom_sync_loop (void *const this_gen)
static void | metronom_start_sync_thread (metronom_clock_private_t *this_priv)
static void | metronom_stop_sync_thread (metronom_clock_private_t *this_priv)
static int | metronom_register_scr (metronom_clock_t *this, scr_plugin_t *scr)
static void | metronom_unregister_scr (metronom_clock_t *this, scr_plugin_t *scr)
static void | metronom_exit (metronom_t *this_gen)
static void | metronom_clock_exit (metronom_clock_t *this)
static void | metronom_base_av_offs_hook (void *this_gen, xine_cfg_entry_t *entry)
metronom_t * | _x_metronom_init (int have_video, int have_audio, xine_t *xine)
static void | metronom_sync_hook (void *this_gen, xine_cfg_entry_t *entry)
metronom_clock_t * | _x_metronom_clock_init (xine_t *xine)

## Macro Definition Documentation

## ◆ abs

#define abs | ( |  | x | ) | ( ((x)<0) ? -(x) : (x) )

## ◆ AUDIO_DRIFT_TOLERANCE

#define AUDIO_DRIFT_TOLERANCE 45000

## ◆ AUDIO_SAMPLE_LD

#define AUDIO_SAMPLE_LD 15

## ◆ AUDIO_SAMPLE_MASK

#define AUDIO_SAMPLE_MASK (AUDIO_SAMPLE_NUM - 1)

## ◆ AUDIO_SAMPLE_NUM

#define AUDIO_SAMPLE_NUM (1 << AUDIO_SAMPLE_LD)

## ◆ BOUNCE_MAX

#define BOUNCE_MAX 360000

## ◆ LOG_MODULE

#define LOG_MODULE "metronom"

## ◆ LOG_VERBOSE

#define LOG_VERBOSE

## ◆ MASK_PTS

#define MASK_PTS (1 << 19) /* 5.825 s */

## ◆ MAX_SCR_PROVIDERS

#define MAX_SCR_PROVIDERS 10

## ◆ MAX_SPEED_CHANGE_CALLBACKS

#define MAX_SPEED_CHANGE_CALLBACKS 16

## ◆ METRONOM_CLOCK_INTERNAL

#define METRONOM_CLOCK_INTERNAL

## ◆ START_PTS

#define START_PTS 0

## ◆ STOP_PTS

#define STOP_PTS ~0

## ◆ VIDEO_DRIFT_TOLERANCE

#define VIDEO_DRIFT_TOLERANCE 45000

## ◆ VIDEO_PREDICTION_MODE

#define VIDEO_PREDICTION_MODE 0 /* use pts + frame duration */

## ◆ VIDEO_PTS_MODE

#define VIDEO_PTS_MODE 1 /* use only pts */

## Function Documentation

## ◆ _x_metronom_clock_init()

metronom_clock_t * _x_metronom_clock_init | ( | xine_t * | xine | ) |

References _, metronom_clock_s::adjust_clock, metronom_clock_s::get_current_time, metronom_clock_s::get_option, metronom_clock_private_t::mct, metronom_adjust_clock(), metronom_clock_exit(), metronom_clock_get_option(), metronom_clock_set_option(), metronom_get_current_time(), metronom_register_scr(), metronom_register_speed_change_callback(), metronom_resume_clock(), metronom_set_speed(), metronom_start_clock(), metronom_stop_clock(), metronom_sync_hook(), metronom_unregister_scr(), metronom_unregister_speed_change_callback(), metronom_clock_private_t::next_sync_pts, NULL, metronom_clock_private_t::providers, metronom_clock_s::register_scr, metronom_clock_s::register_speed_change_callback, metronom_clock_s::set_option, metronom_clock_private_t::speed_change_callbacks, metronom_clock_private_t::speed_change_used, STOP_PTS, metronom_clock_private_t::sync_thread_state, unixscr_init(), metronom_clock_s::unregister_scr, metronom_clock_s::unregister_speed_change_callback, and metronom_clock_private_t::uscr.

Referenced by xine_init().

## ◆ _x_metronom_init()

metronom_t * _x_metronom_init | ( | int | have_video,
|  | int | have_audio,
|  | xine_t * | xine
| ) |  |

References _, xine_s::config, metronom_base_av_offs_hook(), metronom_exit(), metronom_get_option(), metronom_got_audio_samples(), metronom_got_spu_packet(), metronom_got_video_frame(), metronom_handle_audio_discontinuity(), metronom_handle_video_discontinuity(), metronom_set_audio_rate(), metronom_set_master(), metronom_set_option(), NULL, PREBUFFER_PTS_OFFSET, and config_values_s::register_num.

Referenced by fftgraph_port_open(), fftscope_port_open(), fooviz_open_plugin(), goom_open_plugin(), oscope_port_open(), tdaan_port_open(), and xine_stream_new().

## ◆ get_master_scr()

static scr_plugin_t * get_master_scr | ( | metronom_clock_t * | this | ) |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, NULL, metronom_clock_private_t::providers, XINE_VERBOSITY_NONE, and xprintf.

Referenced by metronom_register_scr(), and metronom_unregister_scr().

## ◆ metronom_adjust_clock()

static void metronom_adjust_clock | ( | metronom_clock_t * | this,
|  | int64_t | desired_pts
| ) |  |
| static

References MASK_PTS, metronom_clock_private_t::mct, metronom_clock_private_t::next_sync_pts, and STOP_PTS.

Referenced by _x_metronom_clock_init().

## ◆ metronom_base_av_offs_hook()

static void metronom_base_av_offs_hook | ( | void * | this_gen,
|  | xine_cfg_entry_t * | entry
| ) |  |
| static

References metronom_impl_t::base_av_offset, and xine_cfg_entry_s::num_value.

Referenced by _x_metronom_init().

## ◆ metronom_clock_exit()

static void metronom_clock_exit | ( | metronom_clock_t * | this | ) |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_stop_sync_thread(), NULL, and metronom_clock_private_t::providers.

Referenced by _x_metronom_clock_init().

## ◆ metronom_clock_get_option()

static int64_t metronom_clock_get_option | ( | metronom_clock_t * | this,
|  | int | option
| ) |  |
| static

References CLOCK_SCR_ADJUSTABLE, XINE_VERBOSITY_NONE, and xprintf.

Referenced by _x_metronom_clock_init().

## ◆ metronom_clock_set_option()

static void metronom_clock_set_option | ( | metronom_clock_t * | this,
|  | int | option,
|  | int64_t | value
| ) |  |
| static

References CLOCK_SCR_ADJUSTABLE, XINE_VERBOSITY_NONE, and xprintf.

Referenced by _x_metronom_clock_init().

## ◆ metronom_exit()

static void metronom_exit | ( | metronom_t * | this_gen | ) |
| static

References NULL.

Referenced by _x_metronom_init().

## ◆ metronom_get_current_time()

static int64_t metronom_get_current_time | ( | metronom_clock_t * | this | ) |
| static

References MASK_PTS, MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_clock_private_t::next_sync_pts, and metronom_clock_private_t::providers.

Referenced by _x_metronom_clock_init().

## ◆ metronom_get_option()

static int64_t metronom_get_option | ( | metronom_t * | this_gen,
|  | int | option
| ) |  |
| static

References METRONOM_AV_OFFSET, METRONOM_FRAME_DURATION, METRONOM_NO_LOCK, METRONOM_PREBUFFER, METRONOM_SPU_OFFSET, METRONOM_VDR_TRICK_PTS, METRONOM_VPTS, METRONOM_VPTS_OFFSET, METRONOM_WAITING, XINE_VERBOSITY_NONE, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_got_audio_samples()

static int64_t metronom_got_audio_samples | ( | metronom_t * | this_gen,
|  | int64_t | pts,
|  | int | nsamples
| ) |  |
| static

References abs, AUDIO_DRIFT_TOLERANCE, AUDIO_SAMPLE_LD, AUDIO_SAMPLE_MASK, AUDIO_SAMPLE_NUM, BOUNCE_MAX, lprintf, METRONOM_LOCK, METRONOM_NO_LOCK, METRONOM_VPTS, METRONOM_VPTS_OFFSET, XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_got_spu_packet()

static int64_t metronom_got_spu_packet | ( | metronom_t * | this_gen,
|  | int64_t | pts
| ) |  |
| static

References METRONOM_LOCK, METRONOM_NO_LOCK, METRONOM_SPU_OFFSET, and METRONOM_VPTS_OFFSET.

Referenced by _x_metronom_init().

## ◆ metronom_got_video_frame()

static void metronom_got_video_frame | ( | metronom_t * | this_gen,
|  | vo_frame_t * | img
| ) |  |
| static

References abs, BOUNCE_MAX, vo_frame_s::duration, lprintf, METRONOM_AV_OFFSET, METRONOM_LOCK, METRONOM_NO_LOCK, METRONOM_VPTS, METRONOM_VPTS_OFFSET, vo_frame_s::pts, VIDEO_DRIFT_TOLERANCE, VIDEO_PREDICTION_MODE, VIDEO_PTS_MODE, vo_frame_s::vpts, XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_handle_audio_discontinuity()

static void metronom_handle_audio_discontinuity | ( | metronom_t * | this_gen,
|  | int | type,
|  | int64_t | disc_off
| ) |  |
| static

References DISC_ABSOLUTE, DISC_GAPLESS, metronom_handle_discontinuity(), type, XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_handle_discontinuity()

static int metronom_handle_discontinuity | ( | metronom_impl_t * | this,
|  | int | type,
|  | int | try,
|  | int64_t | disc_off
| ) |  |
| static

References BOUNCE_MAX, DISC_ABSOLUTE, DISC_GAPLESS, DISC_RELATIVE, DISC_STREAMSEEK, DISC_STREAMSTART, lprintf, metronom_vdr_hack_disc(), mode(), type, xine_uint_mul_div(), xine_usec_sleep(), XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by metronom_handle_audio_discontinuity(), and metronom_handle_video_discontinuity().

## ◆ metronom_handle_vdr_trick_pts()

static void metronom_handle_vdr_trick_pts | ( | metronom_impl_t * | this,
|  | int64_t | pts
| ) |  |
| static

References XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by metronom_set_option().

## ◆ metronom_handle_video_discontinuity()

static void metronom_handle_video_discontinuity | ( | metronom_t * | this_gen,
|  | int | type,
|  | int64_t | disc_off
| ) |  |
| static

References _x_assert, DISC_ABSOLUTE, DISC_GAPLESS, metronom_handle_discontinuity(), type, XINE_VERBOSITY_DEBUG, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_register_scr()

static int metronom_register_scr | ( | metronom_clock_t * | this,
|  | scr_plugin_t * | scr
| ) |  |
| static

References scr_plugin_s::clock, get_master_scr(), scr_plugin_s::interface_version, MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_start_sync_thread(), metronom_clock_private_t::providers, XINE_VERBOSITY_NONE, and xprintf.

Referenced by _x_metronom_clock_init().

## ◆ metronom_register_speed_change_callback()

static void metronom_register_speed_change_callback | ( | metronom_clock_t * | this,
|  | xine_speed_change_cb_t * | callback,
|  | void * | user_data
| ) |  |
| static

References MAX_SPEED_CHANGE_CALLBACKS, metronom_clock_private_t::mct, NULL, metronom_clock_private_t::speed_change_callbacks, metronom_clock_private_t::speed_change_data, metronom_clock_private_t::speed_change_used, and user_data().

Referenced by _x_metronom_clock_init().

## ◆ metronom_resume_clock()

static void metronom_resume_clock | ( | metronom_clock_t * | this | ) |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_clock_private_t::providers, metronom_clock_private_t::speed_change_callbacks, metronom_clock_private_t::speed_change_data, and XINE_FINE_SPEED_NORMAL.

Referenced by _x_metronom_clock_init().

## ◆ metronom_set_audio_rate()

static void metronom_set_audio_rate | ( | metronom_t * | this_gen,
|  | int64_t | pts_per_smpls
| ) |  |
| static

References AUDIO_SAMPLE_NUM, and lprintf.

Referenced by _x_metronom_init().

## ◆ metronom_set_master()

static void metronom_set_master | ( | metronom_t * | this_gen,
|  | metronom_t * | master
| ) |  |
| static

References METRONOM_LOCK, and metronom_s::set_option.

Referenced by _x_metronom_init().

## ◆ metronom_set_option()

static void metronom_set_option | ( | metronom_t * | this_gen,
|  | int | option,
|  | int64_t | value
| ) |  |
| static

References METRONOM_ADJ_VPTS_OFFSET, METRONOM_AV_OFFSET, metronom_handle_vdr_trick_pts(), METRONOM_LOCK, METRONOM_PREBUFFER, METRONOM_SPU_OFFSET, metronom_vdr_hack_prebuffer(), METRONOM_VDR_TRICK_PTS, XINE_VERBOSITY_LOG, XINE_VERBOSITY_NONE, and xprintf.

Referenced by _x_metronom_init().

## ◆ metronom_set_speed()

static int metronom_set_speed | ( | metronom_clock_t * | this,
|  | int | speed
| ) |  |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_clock_private_t::providers, metronom_clock_s::speed, metronom_clock_private_t::speed_change_callbacks, and metronom_clock_private_t::speed_change_data.

Referenced by _x_metronom_clock_init().

## ◆ metronom_start_clock()

static void metronom_start_clock | ( | metronom_clock_t * | this,
|  | int64_t | pts
| ) |  |
| static

References lprintf, MASK_PTS, MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_clock_private_t::next_sync_pts, metronom_clock_private_t::providers, metronom_clock_s::speed, STOP_PTS, and XINE_FINE_SPEED_NORMAL.

Referenced by _x_metronom_clock_init().

## ◆ metronom_start_sync_thread()

static void metronom_start_sync_thread | ( | metronom_clock_private_t * | this_priv | ) |
| static

References metronom_clock_private_t::mct, metronom_sync_loop(), metronom_clock_private_t::next_sync_pts, NULL, START_PTS, STOP_PTS, metronom_clock_private_t::sync_thread_state, XINE_VERBOSITY_NONE, and xprintf.

Referenced by metronom_register_scr(), and metronom_sync_hook().

## ◆ metronom_stop_clock()

static void metronom_stop_clock | ( | metronom_clock_t * | this | ) |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_clock_private_t::providers, metronom_clock_private_t::speed_change_callbacks, metronom_clock_private_t::speed_change_data, and XINE_SPEED_PAUSE.

Referenced by _x_metronom_clock_init().

## ◆ metronom_stop_sync_thread()

static void metronom_stop_sync_thread | ( | metronom_clock_private_t * | this_priv | ) |
| static

References metronom_clock_private_t::mct, metronom_clock_private_t::next_sync_pts, NULL, STOP_PTS, and metronom_clock_private_t::sync_thread_state.

Referenced by metronom_clock_exit(), metronom_sync_hook(), and metronom_unregister_scr().

## ◆ metronom_sync_hook()

static void metronom_sync_hook | ( | void * | this_gen,
|  | xine_cfg_entry_t * | entry
| ) |  |
| static

References metronom_start_sync_thread(), metronom_stop_sync_thread(), metronom_clock_private_t::next_sync_pts, xine_cfg_entry_s::num_value, metronom_clock_private_t::providers, START_PTS, STOP_PTS, and metronom_clock_private_t::sync_thread_state.

Referenced by _x_metronom_clock_init().

## ◆ metronom_sync_loop()

static void * metronom_sync_loop | ( | void *const | this_gen | ) |
| static

References MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, NULL, metronom_clock_private_t::providers, and xine_gettime().

Referenced by metronom_start_sync_thread().

## ◆ metronom_unregister_scr()

static void metronom_unregister_scr | ( | metronom_clock_t * | this,
|  | scr_plugin_t * | scr
| ) |  |
| static

References get_master_scr(), MAX_SCR_PROVIDERS, metronom_clock_private_t::mct, metronom_stop_sync_thread(), now(), NULL, and metronom_clock_private_t::providers.

Referenced by _x_metronom_clock_init().

## ◆ metronom_unregister_speed_change_callback()

static void metronom_unregister_speed_change_callback | ( | metronom_clock_t * | this,
|  | xine_speed_change_cb_t * | callback,
|  | void * | user_data
| ) |  |
| static

References metronom_clock_private_t::mct, NULL, metronom_clock_private_t::speed_change_callbacks, metronom_clock_private_t::speed_change_data, metronom_clock_private_t::speed_change_used, and user_data().

Referenced by _x_metronom_clock_init().

## ◆ metronom_vdr_hack_disc()

static void metronom_vdr_hack_disc | ( | metronom_impl_t * | this,
|  | int64_t | pts_offs
| ) |  |
| static

Referenced by metronom_handle_discontinuity().

## ◆ metronom_vdr_hack_prebuffer()

static void metronom_vdr_hack_prebuffer | ( | metronom_impl_t * | this,
|  | int64_t | pts
| ) |  |
| static

Referenced by metronom_set_option().

## ◆ unixscr_adjust()

static void unixscr_adjust | ( | scr_plugin_t * | scr,
|  | int64_t | vpts
| ) |  |
| static

References NULL, v, xine_monotonic_clock(), xine_refs_add(), xine_rwlock_unlock, and xine_rwlock_wrlock.

Referenced by unixscr_init().

## ◆ unixscr_exit()

static void unixscr_exit | ( | scr_plugin_t * | scr | ) |
| static

References xine_refs_get(), xine_refs_sub(), and xine_rwlock_destroy.

Referenced by unixscr_init().

## ◆ unixscr_get_current()

static int64_t unixscr_get_current | ( | scr_plugin_t * | scr | ) |
| static

References NULL, v, xine_monotonic_clock(), xine_refs_get(), xine_rwlock_rdlock, and xine_rwlock_unlock.

Referenced by unixscr_init().

## ◆ unixscr_get_priority()

static int unixscr_get_priority | ( | scr_plugin_t * | scr | ) |
| static

Referenced by unixscr_init().

## ◆ unixscr_init()

static scr_plugin_t * unixscr_init | ( | void * | this_gen | ) |
| static

References lprintf, NULL, unixscr_adjust(), unixscr_exit(), unixscr_get_current(), unixscr_get_priority(), unixscr_set_speed(), unixscr_start(), v, xine_refs_init(), and xine_rwlock_init_default.

Referenced by _x_metronom_clock_init().

## ◆ unixscr_set_pivot()

static void unixscr_set_pivot | ( | unixscr_t * | this | ) |
| static

References NULL, v, and xine_monotonic_clock().

Referenced by unixscr_set_speed().

## ◆ unixscr_set_speed()

static int unixscr_set_speed | ( | scr_plugin_t * | scr,
|  | int | speed
| ) |  |
| static

References unixscr_set_pivot(), v, XINE_FINE_SPEED_NORMAL, xine_refs_add(), xine_rwlock_unlock, and xine_rwlock_wrlock.

Referenced by unixscr_init().

## ◆ unixscr_start()

static void unixscr_start | ( | scr_plugin_t * | scr,
|  | int64_t | start_vpts
| ) |  |
| static

References NULL, v, xine_monotonic_clock(), xine_refs_add(), xine_rwlock_unlock, and xine_rwlock_wrlock.

Referenced by unixscr_init().