summaryrefslogtreecommitdiff
path: root/src/xine-engine/xine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xine-engine/xine.c')
-rw-r--r--src/xine-engine/xine.c309
1 files changed, 244 insertions, 65 deletions
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index eae13bec9..aebbffb39 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -36,6 +36,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
+#include <unistd.h>
#if defined (__linux__) || defined (__GLIBC__)
#include <endian.h>
#elif defined (__FreeBSD__)
@@ -132,7 +133,7 @@ static int acquire_allowed_to_block(xine_ticket_t *this) {
unsigned new_size;
for(entry = 0; entry < this->holder_thread_count; ++entry) {
- if(this->holder_threads[entry].holder == own_id) {
+ if(pthread_equal(this->holder_threads[entry].holder, own_id)) {
/* This thread may already hold this ticket */
this->holder_threads[entry].count++;
return (this->holder_threads[entry].count == 1);
@@ -203,7 +204,7 @@ static int release_allowed_to_block(xine_ticket_t *this) {
unsigned entry;
for(entry = 0; entry < this->holder_thread_count; ++entry) {
- if(this->holder_threads[entry].holder == own_id) {
+ if(pthread_equal(this->holder_threads[entry].holder, own_id)) {
this->holder_threads[entry].count--;
return this->holder_threads[entry].count == 0;
}
@@ -303,10 +304,10 @@ static void ticket_dispose(xine_ticket_t *this) {
free(this);
}
-static xine_ticket_t *ticket_init(void) {
+static xine_ticket_t *XINE_MALLOC ticket_init(void) {
xine_ticket_t *port_ticket;
- port_ticket = (xine_ticket_t *) xine_xmalloc(sizeof(xine_ticket_t));
+ port_ticket = calloc(1, sizeof(xine_ticket_t));
port_ticket->acquire_nonblocking = ticket_acquire_nonblocking;
port_ticket->acquire = ticket_acquire;
@@ -329,17 +330,20 @@ static xine_ticket_t *ticket_init(void) {
static void set_speed_internal (xine_stream_t *stream, int speed) {
xine_t *xine = stream->xine;
+ int old_speed = xine->clock->speed;
- if (xine->clock->speed != XINE_SPEED_PAUSE && speed == XINE_SPEED_PAUSE)
+ if (old_speed != XINE_SPEED_PAUSE && speed == XINE_SPEED_PAUSE)
/* get all decoder and post threads in a state where they agree to be blocked */
xine->port_ticket->revoke(xine->port_ticket, 0);
- if (xine->clock->speed == XINE_SPEED_PAUSE && speed != XINE_SPEED_PAUSE)
+ if (old_speed == XINE_SPEED_PAUSE && speed != XINE_SPEED_PAUSE)
/* all decoder and post threads may continue now */
xine->port_ticket->issue(xine->port_ticket, 0);
- stream->xine->clock->set_fine_speed (stream->xine->clock, speed);
-
+ if (old_speed != XINE_SPEED_PAUSE && speed == XINE_SPEED_PAUSE)
+ /* set master clock so audio_out loop can pause in a safe place */
+ stream->xine->clock->set_fine_speed (stream->xine->clock, speed);
+
/* see coment on audio_out loop about audio_paused */
if( stream->audio_out ) {
xine->port_ticket->acquire(xine->port_ticket, 1);
@@ -349,6 +353,10 @@ static void set_speed_internal (xine_stream_t *stream, int speed) {
xine->port_ticket->release(xine->port_ticket, 1);
}
+
+ if (old_speed == XINE_SPEED_PAUSE || speed != XINE_SPEED_PAUSE)
+ /* master clock is set after resuming the audio device (audio_out loop may continue) */
+ stream->xine->clock->set_fine_speed (stream->xine->clock, speed);
}
@@ -418,6 +426,7 @@ void xine_stop (xine_stream_t *stream) {
static void close_internal (xine_stream_t *stream) {
int i ;
+ int gapless_switch = stream->gapless_switch;
if( stream->slave ) {
xine_close( stream->slave );
@@ -428,7 +437,7 @@ static void close_internal (xine_stream_t *stream) {
}
}
- if( !stream->gapless_switch ) {
+ if( !gapless_switch ) {
/* make sure that other threads cannot change the speed, especially pauseing the stream */
pthread_mutex_lock(&stream->speed_change_lock);
stream->ignore_speed_change = 1;
@@ -444,7 +453,7 @@ static void close_internal (xine_stream_t *stream) {
stop_internal( stream );
- if( !stream->gapless_switch ) {
+ if( !gapless_switch ) {
if (stream->video_out)
stream->video_out->set_property(stream->video_out, VO_PROP_DISCARD_FRAMES, 0);
if (stream->audio_out)
@@ -552,7 +561,7 @@ static int stream_rewire_video(xine_post_out_t *output, void *data)
return 1;
}
-void xine_dispose_internal (xine_stream_t *stream);
+static void xine_dispose_internal (xine_stream_t *stream);
xine_stream_t *xine_stream_new (xine_t *this,
xine_audio_port_t *ao, xine_video_port_t *vo) {
@@ -569,7 +578,7 @@ xine_stream_t *xine_stream_new (xine_t *this,
pthread_mutex_lock (&this->streams_lock);
- stream = (xine_stream_t *) xine_xmalloc (sizeof (xine_stream_t)) ;
+ stream = (xine_stream_t *) calloc (1, sizeof (xine_stream_t)) ;
stream->current_extra_info = malloc( sizeof( extra_info_t ) );
stream->audio_decoder_extra_info = malloc( sizeof( extra_info_t ) );
stream->video_decoder_extra_info = malloc( sizeof( extra_info_t ) );
@@ -595,6 +604,7 @@ xine_stream_t *xine_stream_new (xine_t *this,
stream->early_finish_event = 0;
stream->delay_finish_event = 0;
stream->gapless_switch = 0;
+ stream->keep_ao_driver_open = 0;
stream->video_out = vo;
if (vo)
@@ -628,6 +638,7 @@ xine_stream_t *xine_stream_new (xine_t *this,
pthread_mutex_init (&stream->meta_mutex, NULL);
pthread_mutex_init (&stream->demux_lock, NULL);
pthread_mutex_init (&stream->demux_mutex, NULL);
+ pthread_cond_init (&stream->demux_resume, NULL);
pthread_mutex_init (&stream->event_queues_lock, NULL);
pthread_mutex_init (&stream->counter_lock, NULL);
pthread_cond_init (&stream->counter_changed, NULL);
@@ -733,7 +744,7 @@ xine_stream_t *xine_stream_new (xine_t *this,
}
void _x_mrl_unescape(char *mrl) {
- int i, len = strlen(mrl);
+ size_t i, len = strlen(mrl);
for (i = 0; i < len; i++) {
if ((mrl[i]=='%') && (i<(len-2))) {
@@ -780,9 +791,23 @@ void _x_flush_events_queues (xine_stream_t *stream) {
pthread_mutex_unlock (&stream->event_queues_lock);
}
-/*static*/ int open_internal (xine_stream_t *stream, const char *mrl) {
+static inline int _x_path_looks_like_mrl (const char *path)
+{
+ if ((*path & 0xDF) < 'A' || (*path & 0xDF) > 'Z')
+ return 0;
+
+ for (++path; *path; ++path)
+ if ((*path != '-' && *path < '0') || (*path > '9' && *path < 'A') ||
+ (*path > 'Z' && *path < 'a') || *path > 'z')
+ break;
+
+ return path[0] == ':' && path[1] == '/';
+}
+
+static int open_internal (xine_stream_t *stream, const char *mrl) {
const char *stream_setup = NULL;
+ const char *mrl_proto = NULL;
int no_cache = 0;
if (!mrl) {
@@ -806,16 +831,31 @@ void _x_flush_events_queues (xine_stream_t *stream) {
/*
* look for a stream_setup in MRL and try finding an input plugin
*/
+ stream_setup = strchr (mrl, '#');
if (isalpha (*mrl))
{
- stream_setup = mrl + 1;
- while (isalnum (*stream_setup) || *stream_setup == '+' || *stream_setup == '-' || *stream_setup == '.')
- ++stream_setup;
- if (stream_setup[0] == ':' && stream_setup[1] == '/')
- stream_setup = strchr (mrl, '#');
- else
- stream_setup = NULL;
+ mrl_proto = mrl + 1;
+ while (isalnum (*mrl_proto) || *mrl_proto == '+' || *mrl_proto == '-' || *mrl_proto == '.')
+ ++mrl_proto;
+ if (!mrl_proto[0] || mrl_proto[0] != ':' || mrl_proto[1] != '/')
+ mrl_proto = NULL;
+ }
+
+ /* for raw filenames we must try every '#' checking if it is part of the filename */
+ if( !mrl_proto && stream_setup) {
+ struct stat stat_buf;
+ int res;
+
+ while( stream_setup ) {
+ char *raw_filename = strndup (mrl, stream_setup - mrl);
+
+ res = stat(raw_filename, &stat_buf);
+ free(raw_filename);
+ if( !res )
+ break;
+ stream_setup = strchr(stream_setup + 1, '#');
+ }
}
{
@@ -824,8 +864,10 @@ void _x_flush_events_queues (xine_stream_t *stream) {
/*
* find an input plugin
*/
-
- if ((stream->input_plugin = _x_find_input_plugin (stream, input_source))) {
+ stream->input_plugin = _x_find_input_plugin (stream, input_source);
+ free(input_source);
+
+ if ( stream->input_plugin ) {
int res;
xine_log (stream->xine, XINE_LOG_MSG, _("xine: found input plugin : %s\n"),
@@ -840,7 +882,6 @@ void _x_flush_events_queues (xine_stream_t *stream) {
case 1: /* Open successfull */
break;
case -1: /* Open unsuccessfull, but correct plugin */
- free(input_source);
stream->err = XINE_ERROR_INPUT_FAILED;
_x_flush_events_queues (stream);
return 0;
@@ -851,8 +892,6 @@ void _x_flush_events_queues (xine_stream_t *stream) {
stream->err = XINE_ERROR_INPUT_FAILED;
}
}
-
- free(input_source);
}
if (!stream->input_plugin) {
@@ -917,6 +956,7 @@ void _x_flush_events_queues (xine_stream_t *stream) {
memcpy(filename, tmp, strlen(tmp));
filename[strlen(tmp)] = '\0';
}
+ _x_mrl_unescape(filename);
xine_log(stream->xine, XINE_LOG_MSG, _("xine: join rip input plugin\n"));
input_saver = _x_rip_plugin_get_instance (stream, filename);
@@ -1091,7 +1131,9 @@ void _x_flush_events_queues (xine_stream_t *stream) {
memcpy(subtitle_mrl, tmp, strlen(tmp));
subtitle_mrl[strlen(tmp)] = '\0';
}
- _x_mrl_unescape(subtitle_mrl);
+ /* unescape for xine_open() if the MRL looks like a raw pathname */
+ if (!_x_path_looks_like_mrl(subtitle_mrl))
+ _x_mrl_unescape(subtitle_mrl);
stream->slave = xine_stream_new (stream->xine, NULL, stream->video_out );
stream->slave_affection = XINE_MASTER_SLAVE_PLAY | XINE_MASTER_SLAVE_STOP;
if( xine_open( stream->slave, subtitle_mrl ) ) {
@@ -1152,6 +1194,27 @@ void _x_flush_events_queues (xine_stream_t *stream) {
/* enable buffered input plugin (request optimizer) */
stream->input_plugin = _x_cache_plugin_get_instance(stream, 0);
+ /* Let the plugin request a specific demuxer (if the user hasn't).
+ * This overrides find-by-content & find-by-extension.
+ */
+ if (!stream->demux_plugin)
+ {
+ char *default_demux = NULL;
+ stream->input_plugin->get_optional_data (stream->input_plugin, &default_demux, INPUT_OPTIONAL_DATA_DEMUXER);
+ if (default_demux)
+ {
+ stream->demux_plugin = _x_find_demux_plugin_by_name (stream, default_demux, stream->input_plugin);
+ if (stream->demux_plugin)
+ {
+ lprintf ("demux and input plugin found\n");
+ _x_meta_info_set_utf8 (stream, XINE_META_INFO_SYSTEMLAYER,
+ stream->demux_plugin->demux_class->get_identifier (stream->demux_plugin->demux_class));
+ }
+ else
+ xine_log (stream->xine, XINE_LOG_MSG, _("xine: couldn't load plugin-specified demux %s for >%s<\n"), default_demux, mrl);
+ }
+ }
+
if (!stream->demux_plugin) {
/*
@@ -1290,6 +1353,7 @@ static int play_internal (xine_stream_t *stream, int start_pos, int start_time)
pthread_mutex_lock( &stream->demux_lock );
/* demux_lock taken. now demuxer is suspended */
stream->demux_action_pending = 0;
+ pthread_cond_signal(&stream->demux_resume);
/* set normal speed again (now that demuxer/input pair is suspended)
* some input plugin may have changed speed by itself, we must ensure
@@ -1403,7 +1467,7 @@ int xine_eject (xine_stream_t *stream) {
return status;
}
-void xine_dispose_internal (xine_stream_t *stream) {
+static void xine_dispose_internal (xine_stream_t *stream) {
xine_list_iterator_t *ite;
@@ -1416,6 +1480,7 @@ void xine_dispose_internal (xine_stream_t *stream) {
pthread_mutex_destroy (&stream->current_extra_info_lock);
pthread_cond_destroy (&stream->counter_changed);
pthread_mutex_destroy (&stream->demux_mutex);
+ pthread_cond_destroy (&stream->demux_resume);
pthread_mutex_destroy (&stream->demux_lock);
pthread_mutex_destroy (&stream->first_frame_lock);
pthread_cond_destroy (&stream->first_frame_reached);
@@ -1510,7 +1575,7 @@ xine_t *xine_new (void) {
int i_err;
#endif
- this = xine_xmalloc (sizeof (xine_t));
+ this = calloc(1, sizeof (xine_t));
if (!this)
_x_abort();
@@ -1599,8 +1664,7 @@ static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) {
xine_t *this = (xine_t *)this_gen;
char *homedir_trail_slash;
- homedir_trail_slash = (char *)malloc(strlen(xine_get_homedir()) + 2);
- sprintf(homedir_trail_slash, "%s/", xine_get_homedir());
+ asprintf(&homedir_trail_slash, "%s/", xine_get_homedir());
if (entry->str_value[0] &&
(entry->str_value[0] != '/' || strstr(entry->str_value, "/.") ||
strcmp(entry->str_value, xine_get_homedir()) == 0 ||
@@ -1627,6 +1691,12 @@ void xine_init (xine_t *this) {
static const char *demux_strategies[] = {"default", "reverse", "content",
"extension", NULL};
+ /*
+ * locks
+ */
+ pthread_mutex_init (&this->streams_lock, NULL);
+ pthread_mutex_init (&this->log_lock, NULL);
+
/* initialize color conversion tables and functions */
init_yuv_conversion();
@@ -1708,12 +1778,6 @@ void xine_init (xine_t *this) {
this->streams = xine_list_new();
/*
- * locks
- */
- pthread_mutex_init (&this->streams_lock, NULL);
- pthread_mutex_init (&this->log_lock, NULL);
-
- /*
* start metronom clock
*/
@@ -1899,50 +1963,98 @@ int xine_get_pos_length (xine_stream_t *stream, int *pos_stream,
return 1;
}
-int xine_get_current_frame (xine_stream_t *stream, int *width, int *height,
- int *ratio_code, int *format,
- uint8_t *img) {
+static int _x_get_current_frame_data (xine_stream_t *stream,
+ xine_current_frame_data_t *data,
+ int flags, int img_size_unknown) {
vo_frame_t *frame;
+ size_t required_size;
stream->xine->port_ticket->acquire(stream->xine->port_ticket, 0);
frame = stream->video_out->get_last_frame (stream->video_out);
stream->xine->port_ticket->release(stream->xine->port_ticket, 0);
- if (!frame)
+ if (!frame) {
+ data->img_size = 0;
return 0;
+ }
- *width = frame->width;
- *height = frame->height;
+ data->width = frame->width;
+ data->height = frame->height;
+ data->crop_left = frame->crop_left;
+ data->crop_right = frame->crop_right;
+ data->crop_top = frame->crop_top;
+ data->crop_bottom = frame->crop_bottom;
- *ratio_code = 10000.0 * frame->ratio;
+ data->ratio_code = 10000.0 * frame->ratio;
/* make ratio_code backward compatible */
#define RATIO_LIKE(a, b) ((b) - 1 <= (a) && (a) <= 1 + (b))
- if (RATIO_LIKE(*ratio_code, 10000))
- *ratio_code = XINE_VO_ASPECT_SQUARE;
- else if (RATIO_LIKE(*ratio_code, 13333))
- *ratio_code = XINE_VO_ASPECT_4_3;
- else if (RATIO_LIKE(*ratio_code, 17778))
- *ratio_code = XINE_VO_ASPECT_ANAMORPHIC;
- else if (RATIO_LIKE(*ratio_code, 21100))
- *ratio_code = XINE_VO_ASPECT_DVB;
-
- *format = frame->format;
-
- if (img){
+ if (RATIO_LIKE(data->ratio_code, 10000))
+ data->ratio_code = XINE_VO_ASPECT_SQUARE;
+ else if (RATIO_LIKE(data->ratio_code, 13333))
+ data->ratio_code = XINE_VO_ASPECT_4_3;
+ else if (RATIO_LIKE(data->ratio_code, 17778))
+ data->ratio_code = XINE_VO_ASPECT_ANAMORPHIC;
+ else if (RATIO_LIKE(data->ratio_code, 21100))
+ data->ratio_code = XINE_VO_ASPECT_DVB;
+
+ data->format = frame->format;
+ data->interlaced = frame->progressive_frame ? 0 : (2 - frame->top_field_first);
+
+ switch (frame->format) {
+
+ case XINE_IMGFMT_YV12:
+ required_size = frame->width * frame->height
+ + ((frame->width + 1) / 2) * ((frame->height + 1) / 2)
+ + ((frame->width + 1) / 2) * ((frame->height + 1) / 2);
+ break;
+
+ case XINE_IMGFMT_YUY2:
+ required_size = frame->width * frame->height
+ + ((frame->width + 1) / 2) * frame->height
+ + ((frame->width + 1) / 2) * frame->height;
+ break;
+
+ default:
+ if (data->img || (flags & XINE_FRAME_DATA_ALLOCATE_IMG)) {
+ xprintf (stream->xine, XINE_VERBOSITY_DEBUG,
+ "xine: error, snapshot function not implemented for format 0x%x\n", frame->format);
+ _x_abort ();
+ }
+
+ required_size = 0;
+ }
+
+ if (flags & XINE_FRAME_DATA_ALLOCATE_IMG) {
+ /* return allocated buffer size */
+ data->img_size = required_size;
+ /* allocate img or fail */
+ if (!(data->img = calloc(1, required_size)))
+ return 0;
+ } else {
+ /* fail if supplied buffer is to small */
+ if (data->img && !img_size_unknown && data->img_size < required_size) {
+ data->img_size = required_size;
+ return 0;
+ }
+ /* return used buffer size */
+ data->img_size = required_size;
+ }
+
+ if (data->img) {
switch (frame->format) {
case XINE_IMGFMT_YV12:
yv12_to_yv12(
/* Y */
frame->base[0], frame->pitches[0],
- img, frame->width,
+ data->img, frame->width,
/* U */
frame->base[1], frame->pitches[1],
- img+frame->width*frame->height, frame->width/2,
+ data->img+frame->width*frame->height, frame->width/2,
/* V */
frame->base[2], frame->pitches[2],
- img+frame->width*frame->height+frame->width*frame->height/4, frame->width/2,
+ data->img+frame->width*frame->height+frame->width*frame->height/4, frame->width/2,
/* width x height */
frame->width, frame->height);
break;
@@ -1952,7 +2064,7 @@ int xine_get_current_frame (xine_stream_t *stream, int *width, int *height,
/* src */
frame->base[0], frame->pitches[0],
/* dst */
- img, frame->width*2,
+ data->img, frame->width*2,
/* width x height */
frame->width, frame->height);
break;
@@ -1966,6 +2078,69 @@ int xine_get_current_frame (xine_stream_t *stream, int *width, int *height,
return 1;
}
+int xine_get_current_frame_data (xine_stream_t *stream,
+ xine_current_frame_data_t *data,
+ int flags) {
+
+ return _x_get_current_frame_data(stream, data, flags, 0);
+}
+
+int xine_get_current_frame_alloc (xine_stream_t *stream, int *width, int *height,
+ int *ratio_code, int *format,
+ uint8_t **img, int *img_size) {
+
+ int result;
+ xine_current_frame_data_t data;
+
+ memset(&data, 0, sizeof (data));
+
+ result = _x_get_current_frame_data(stream, &data, img ? XINE_FRAME_DATA_ALLOCATE_IMG : 0, 0);
+ if (width) *width = data.width;
+ if (height) *height = data.height;
+ if (ratio_code) *ratio_code = data.ratio_code;
+ if (format) *format = data.format;
+ if (img_size) *img_size = data.img_size;
+ if (img) *img = data.img;
+ return result;
+}
+
+int xine_get_current_frame_s (xine_stream_t *stream, int *width, int *height,
+ int *ratio_code, int *format,
+ uint8_t *img, int *img_size) {
+ int result;
+ xine_current_frame_data_t data;
+
+ memset(&data, 0, sizeof (data));
+ data.img = img;
+ if (img_size)
+ data.img_size = *img_size;
+
+ result = _x_get_current_frame_data(stream, &data, 0, 0);
+ if (width) *width = data.width;
+ if (height) *height = data.height;
+ if (ratio_code) *ratio_code = data.ratio_code;
+ if (format) *format = data.format;
+ if (img_size) *img_size = data.img_size;
+ return result;
+}
+
+int xine_get_current_frame (xine_stream_t *stream, int *width, int *height,
+ int *ratio_code, int *format,
+ uint8_t *img) {
+ int result;
+ xine_current_frame_data_t data;
+
+ memset(&data, 0, sizeof (data));
+ data.img = img;
+
+ result = _x_get_current_frame_data(stream, &data, 0, 1);
+ if (width) *width = data.width;
+ if (height) *height = data.height;
+ if (ratio_code) *ratio_code = data.ratio_code;
+ if (format) *format = data.format;
+ return result;
+}
+
int xine_get_video_frame (xine_stream_t *stream,
int timestamp, /* msec */
int *width, int *height,
@@ -2084,7 +2259,10 @@ void xine_log (xine_t *this, int buf, const char *format, ...) {
vsnprintf(buffer, SCRATCH_LINE_LEN_MAX, format, argp);
printf("%s", buffer);
va_end (argp);
- }
+ }
+
+ if (this->log_cb)
+ this->log_cb (this->log_cb_user_data, buf);
}
void xine_vlog(xine_t *this, int buf, const char *format,
@@ -2093,6 +2271,9 @@ void xine_vlog(xine_t *this, int buf, const char *format,
check_log_alloc (this, buf);
this->log_buffers[buf]->scratch_printf(this->log_buffers[buf], format, args);
+
+ if (this->log_cb)
+ this->log_cb (this->log_cb_user_data, buf);
}
char *const *xine_get_log (xine_t *this, int buf) {
@@ -2107,12 +2288,10 @@ char *const *xine_get_log (xine_t *this, int buf) {
}
void xine_register_log_cb (xine_t *this, xine_log_cb_t cb, void *user_data) {
-
- printf ("xine: xine_register_log_cb: not implemented yet.\n");
- _x_abort();
+ this->log_cb = cb;
+ this->log_cb_user_data = user_data;
}
-
int xine_get_error (xine_stream_t *stream) {
return stream->err;
}