diff options
Diffstat (limited to 'src/xine-engine')
-rw-r--r-- | src/xine-engine/demux.c | 2 | ||||
-rw-r--r-- | src/xine-engine/info_helper.c | 4 | ||||
-rw-r--r-- | src/xine-engine/input_rip.c | 7 | ||||
-rw-r--r-- | src/xine-engine/load_plugins.c | 171 | ||||
-rw-r--r-- | src/xine-engine/xine.c | 141 | ||||
-rw-r--r-- | src/xine-engine/xine_interface.c | 2 |
6 files changed, 166 insertions, 161 deletions
diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index 51ed5b39d..c116d407f 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -657,7 +657,7 @@ void _x_demux_send_mrl_reference (xine_stream_t *stream, int alternative, xine_mrl_reference_data_ext_t *e; xine_mrl_reference_data_t *b; } data; - int mrl_len = strlen (mrl); + const size_t mrl_len = strlen (mrl); if (!title) title = ""; diff --git a/src/xine-engine/info_helper.c b/src/xine-engine/info_helper.c index e6d4df7e9..242805915 100644 --- a/src/xine-engine/info_helper.c +++ b/src/xine-engine/info_helper.c @@ -131,7 +131,7 @@ uint32_t _x_stream_info_get_public(xine_stream_t *stream, int info) { * at the end of the string */ static void meta_info_chomp(char *str) { - int i, len; + size_t i, len; len = strlen(str); if (!len) @@ -358,7 +358,7 @@ void _x_meta_info_set_multi(xine_stream_t *stream, int info, ...) { va_list ap; char *args[1025]; char *buf; - int n, len; + size_t n, len; len = n = 0; diff --git a/src/xine-engine/input_rip.c b/src/xine-engine/input_rip.c index 200721dca..8db7eaaf5 100644 --- a/src/xine-engine/input_rip.c +++ b/src/xine-engine/input_rip.c @@ -517,10 +517,9 @@ static void rip_plugin_dispose(input_plugin_t *this_gen) { * returns non-zero, if there was enough space */ static int dir_file_concat(char *target, size_t maxlen, const char *dir, const char *name) { - size_t len_dir, len_name, pos_name = 0; - - len_name = strlen(name); - len_dir = strlen(dir); + size_t len_name = strlen(name); + size_t len_dir = strlen(dir); + size_t pos_name = 0; /* remove slashes */ if (dir[len_dir - 1] == '/') len_dir--; diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 80cfde12c..13f9b94c7 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -313,7 +313,6 @@ static void _insert_node (xine_t *this, const input_info_t *input_old; uint32_t *types; char key[80]; - char desc[100]; int i; _x_assert(list); @@ -378,12 +377,11 @@ static void _insert_node (xine_t *this, entry->priority = decoder_new->priority = decoder_old->priority; snprintf(key, sizeof(key), "engine.decoder_priorities.%s", info->id); - snprintf(desc, sizeof(desc), _("priority for %s decoder"), info->id); /* write the description on the heap because the config system * does not strdup() it, so we have to provide a different pointer * for each decoder */ for (i = 0; catalog->prio_desc[i]; i++); - catalog->prio_desc[i] = strdup(desc); + asprintf(&catalog->prio_desc[i], _("priority for %s decoder"), info->id); this->config->register_num (this->config, key, 0, @@ -556,25 +554,20 @@ static void collect_plugins(xine_t *this, char *path){ dir = opendir(path); if (dir) { struct dirent *pEntry; - size_t path_len, str_size; - char *str = NULL; - path_len = strlen(path); - str_size = path_len * 2 + 2; /* +2 for '/' and '\0' */ - str = malloc(str_size); - xine_fast_memcpy(str, path, path_len); - str[path_len] = '/'; - str[path_len + 1] = '\0'; + size_t path_len = strlen(path); + size_t str_size = path_len * 2 + 2; /* +2 for '/' and '\0' */ + char *str = malloc(str_size); + sprintf(str, "%s/", path); while ((pEntry = readdir (dir)) != NULL) { - size_t new_str_size, d_len; void *lib = NULL; plugin_info_t *info = NULL; struct stat statbuffer; - d_len = strlen(pEntry->d_name); - new_str_size = path_len + d_len + 2; + size_t d_len = strlen(pEntry->d_name); + size_t new_str_size = path_len + d_len + 2; if (str_size < new_str_size) { str_size = new_str_size + new_str_size / 2; str = realloc(str, str_size); @@ -2416,6 +2409,32 @@ void xine_post_dispose(xine_t *xine, xine_post_t *post_gen) { * their disposal if they are still in use => post.c handles the counting for us */ } +/** + * @brief Concantenates an array of strings into a single + * string separated with a given string. + * + * @param strings Array of strings to concatenate. + * @param count Number of elements in the @p strings array. + * @param joining String to use to join the various strings together. + * @param final_length The pre-calculated final length of the string. + */ +static char *_x_concatenate_with_string(char **strings, size_t count, char *joining, size_t final_length) { + size_t i; + char *const result = malloc(final_length+1); /* Better be safe */ + char *str = result; + + size_t pos = 0; + for(i = 0; i < count; i++, strings++) { + if ( *strings ) { + int offset = snprintf(str, final_length, "%s%s", *strings, joining); + str += offset; + final_length -= offset; + } + } + + return result; +} + /* get a list of file extensions for file types supported by xine * the list is separated by spaces * @@ -2423,66 +2442,35 @@ void xine_post_dispose(xine_t *xine, xine_post_t *post_gen) { char *xine_get_file_extensions (xine_t *self) { plugin_catalog_t *catalog = self->plugin_catalog; - int len, pos; - plugin_node_t *node; - char *str; - int list_id, list_size; + int list_id; pthread_mutex_lock (&catalog->lock); - /* calc length of output */ + /* calc length of output string and create an array of strings to + concatenate */ + size_t len = 0; + const int list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); + const char **extensions = calloc(list_size, sizeof(char*)); - len = 0; - list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); for (list_id = 0; list_id < list_size; list_id++) { - demux_class_t *cls; - const char *exts; - - node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); + plugin_node_t *const node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); if (node->plugin_class || _load_plugin_class(self, node, NULL)) { - - cls = (demux_class_t *)node->plugin_class; - - if((exts = cls->get_extensions(cls)) && *exts) - len += strlen(exts) + 1; + demux_class_t *const cls = (demux_class_t *)node->plugin_class; + if( (extensions[list_id] = cls->get_extensions(cls)) != NULL ) + len += strlen(extensions[list_id]) +1; } } - /* create output */ - str = malloc (len); /* '\0' space is already counted in the previous loop */ - pos = 0; - - list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); - for (list_id = 0; list_id < list_size; list_id++) { - demux_class_t *cls; - const char *e; - int l; - - node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); - if (node->plugin_class || _load_plugin_class(self, node, NULL)) { - - cls = (demux_class_t *)node->plugin_class; - - if((e = cls->get_extensions (cls)) && *e) { - l = strlen(e); - memcpy (&str[pos], e, l); - - pos += l; - - /* Don't add ' ' char at the end of str */ - if((pos + 1) < len) { - str[pos] = ' '; - pos++; - } - } - } - } - - str[pos] = 0; + /* create output string */ + char *const result = _x_concatenate_with_string(extensions, list_size, " ", len); + free(extensions); + /* Drop the last whitespace */ + result[len-1] = '\0'; + pthread_mutex_unlock (&catalog->lock); - return str; + return result; } /* get a list of mime types supported by xine @@ -2491,65 +2479,34 @@ char *xine_get_file_extensions (xine_t *self) { char *xine_get_mime_types (xine_t *self) { plugin_catalog_t *catalog = self->plugin_catalog; - int len, pos; - plugin_node_t *node; - char *str; - int list_id, list_size; + int list_id; pthread_mutex_lock (&catalog->lock); /* calc length of output */ - len = 0; - list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); + /* calc length of output string and create an array of strings to + concatenate */ + size_t len = 0; + const int list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); + const char **mimetypes = calloc(list_size, sizeof(char*)); for (list_id = 0; list_id < list_size; list_id++) { - demux_class_t *cls; - const char *s; - - node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); + plugin_node_t *const node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); if (node->plugin_class || _load_plugin_class(self, node, NULL)) { - - cls = (demux_class_t *)node->plugin_class; - - s = cls->get_mimetypes (cls); - if (s) - len += strlen(s); + demux_class_t *const cls = (demux_class_t *)node->plugin_class; + if( (mimetypes[list_id] = cls->get_mimetypes(cls)) != NULL ) + len += strlen(mimetypes[list_id]); } } - /* create output */ - - str = malloc (len+1); - pos = 0; - - list_size = xine_sarray_size (catalog->plugin_lists[PLUGIN_DEMUX - 1]); - - for (list_id = 0; list_id < list_size; list_id++) { - demux_class_t *cls; - const char *s; - int l; + /* create output string */ + char *const result = _x_concatenate_with_string(mimetypes, list_size, "", len); + free(mimetypes); - node = xine_sarray_get (catalog->plugin_lists[PLUGIN_DEMUX - 1], list_id); - if (node->plugin_class || _load_plugin_class(self, node, NULL)) { - - cls = (demux_class_t *)node->plugin_class; - - s = cls->get_mimetypes (cls); - if (s) { - l = strlen(s); - memcpy (&str[pos], s, l); - - pos += l; - } - } - } - - str[pos] = 0; - pthread_mutex_unlock (&catalog->lock); - return str; + return result; } diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index fd10a7401..558aa996e 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -735,7 +735,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))) { @@ -1933,9 +1933,9 @@ int xine_get_pos_length (xine_stream_t *stream, int *pos_stream, return 1; } -static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *height, - int *ratio_code, int *format, - uint8_t **img, int *size, int alloc_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; @@ -1944,42 +1944,49 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he 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; + 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; - *format = frame->format; + data->format = frame->format; + data->interlaced = frame->progressive_frame ? 0 : (2 - frame->top_field_first); - switch (*format) { + switch (frame->format) { case XINE_IMGFMT_YV12: - required_size = *width * *height - + ((*width + 1) / 2) * ((*height + 1) / 2) - + ((*width + 1) / 2) * ((*height + 1) / 2); + 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 = *width * *height - + ((*width + 1) / 2) * *height - + ((*width + 1) / 2) * *height; + required_size = frame->width * frame->height + + ((frame->width + 1) / 2) * frame->height + + ((frame->width + 1) / 2) * frame->height; break; default: - if (*img || alloc_img) { + 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 (); @@ -1988,38 +1995,36 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he required_size = 0; } - if (alloc_img) { - /* return size if requested */ - if (size) - *size = required_size; + if (flags & XINE_FRAME_DATA_ALLOCATE_IMG) { + /* return allocated buffer size */ + data->img_size = required_size; /* allocate img or fail */ - if (!(*img = calloc(1, required_size))) + if (!(data->img = calloc(1, required_size))) return 0; } else { /* fail if supplied buffer is to small */ - if (*img && size && *size < required_size) { - *size = required_size; + if (data->img && !img_size_unknown && data->img_size < required_size) { + data->img_size = required_size; return 0; } - /* return size if requested */ - if (size) - *size = required_size; + /* return used buffer size */ + data->img_size = required_size; } - if (*img) { + 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; @@ -2029,7 +2034,7 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he /* 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; @@ -2043,23 +2048,67 @@ static int _x_get_current_frame_impl (xine_stream_t *stream, int *width, int *he 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 *size) { - uint8_t *no_img = NULL; - return _x_get_current_frame_impl(stream, width, height, ratio_code, format, img ? img : &no_img, size, img != NULL); + 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 *size) { - return (!img || size) && _x_get_current_frame_impl(stream, width, height, ratio_code, format, &img, size, 0); + 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) { - return _x_get_current_frame_impl(stream, width, height, ratio_code, format, &img, NULL, 0); + 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, diff --git a/src/xine-engine/xine_interface.c b/src/xine-engine/xine_interface.c index 597608883..415ceec56 100644 --- a/src/xine-engine/xine_interface.c +++ b/src/xine-engine/xine_interface.c @@ -945,7 +945,7 @@ int _x_message(xine_stream_t *stream, int type, ...) { xine_ui_message_data_t *data; xine_event_t event; const char *explanation; - int size; + size_t size; int n; va_list ap; char *s, *params; |